C++problem Sheet
C++problem Sheet
C++problem Sheet
#include<iostream.h>
#include<conio.h>
void leap(int);
int main()
{
int l;
clrscr();
cout<<"Enter any year:";
cin>>l;
0
leap(l);
getch();
return 0;
}
void leap(int e)
{
if(e%4==0)
{
}
09
cout<<"The entered year is a leap year.";
12
else
{
cout<<"The entered year is not a leap year.";
}
getch();
}
22
int main()
{
clrscr();
cout<<"1+2="<<1+2<<endl;
cout<<"'1'+'2'="<<'1'+'2';
getch();
return 0;
}
0
#include<conio.h>
class employee
{
int emp_code,age,salary;
char emp_name[30];
public:
void getdata();
void putdata();
09
12
};
void employee::getdata()
{
cout<<"Enter employee code:";
cin>>emp_code;
cout<<"Enter employee name:";
22
cin>>emp_name;
cout<<"Enter employee age:";
cin>>age;
cout<<"Enter employee salary:";
cin>>salary;
}
void employee :: putdata()
{
if(age>40 && salary>5000)
{
cout<<"Employee code:"<<emp_code;
cout<<"\nEmployee name:"<<emp_name;
cout<<"\nEmployee age:"<<age;
cout<<"\nEmployee salary:"<<salary;
}
}
int main()
{
employee emp[3];
int i;
clrscr();
for(i=0;i<3;i++)
{
cout<<"*****Details of Employee"<<i+1<<"*****"<<endl;
emp[i].getdata();
}
cout<<"***Employees who's age and salary is more than 40 and 5000 respectively:***"<<endl;
for(i=0;i<3;i++)
0
{
emp[i].putdata();
}
}
getch();
return 0;
09
5. Write a program to find the area of various
12
geometrical shapes by function overloading.
#include<iostream.h>
#include<conio.h>
int area(int);
int area(int,int);
22
float area(float);
float area(float,float);
int main()
{
int s,l,b;
float r,bs,ht;
clrscr();
cout<<"Enter side of square:";
cin>>s;
cout<<"Enter length and breadth of rectangle:";
cin>>l>>b;
cout<<"Enter radius of circle:";
cin>>r;
cout<<"Enter base and height of triangle:";
cin>>bs>>ht;
cout<<"Area of circle:"<<area(s);
cout<<"\nArea of rectangle:"<<area(l,b);
cout<<"\narea of circle:"<<area(r);
cout<<"\nArea of triangle:"<<area(bs,ht);
getch();
return 0;
}
int area(int s)
{
return(s*s);
}
int area(int l, int b)
0
{
return(l*b);
}
float area(float r)
{
}
return(3.14*r*r);
#include <string.h>
class Student {
private:
int rollNo;
char name[10];
int marks;
public:
0
int Student::objectCount = 0;
int main(void) {
Student s1;
s1.getdata();
s1.putdata();
Student s2;
s2.getdata();
s2.putdata();
Student s3;
s3.getdata();
09
12
s3.putdata();
cout << "Total objects created = " <<
Student::objectCount << endl;
return 0;
}
22
int rollNo;
char name[10];
int marks;
static int objectCount;
public:
void getdata();
void putdata();
static void show_count()
{
cout<<"No.ofstudents: "<< objectCount++<<endl;
}
};
void Student :: getdata() {
cout << "Enter roll number: "<<endl;
cin >> rollNo;
cout << "Enter name: "<<endl;
0
cin >> name;
cout << "Enter marks: "<<endl;
cin >> marks; }
void Student :: putdata() {
09
cout<<"Roll Number = "<< rollNo <<endl;
cout<<"Name = "<< name <<endl;
cout<<"Marks = "<< marks <<endl;
cout<<endl; }
int Student::objectCount = 0;
int main()
12
{
clrscr();
Student::show_count();
Student::show_count();
getch();
22
return 0;
class e_bill
{
private:
int c_no;
char c_name[20];
int units;
double bill;
public:
void get()
{
cout<<"Enter Details of Customer Below :: \n" <<endl;
cout<<"Enter Customer No. :: ";
cin>>c_no;
cout<<"\nEnter Customer Name :: ";
cin>>c_name;
cout<<"\nEnter No. of Units used :: ";
0
cin>>units;
}
void put()
{
09
cout<<"\nEntered Details of Customer are :: " <<endl;
cout<<"\nCustomer No. is : "<<c_no;
cout<<"\n\nCustomer Name is : "<<c_name;
cout<<"\n\nNumber of Units Consumed : "<<units;
cout<<"\n\nBill of Customer : "<<bill;
12
}
void calc_bill()
{
if(units<=100)
bill=units*1.20;
22
else if(units<=300)
bill=100*1.20+(units-100)*2;
else
bill=100*1.20+200*2+(units-300)*3;
}
};
int main()
{
e_bill b1;
b1.get();
b1.calc_bill();
b1.put();
cout<<"\n";
return 0;
}
0
inline float square(float n)
{
return(n*n);
}
int main()
{
float n;
clrscr();
cout<<"Enter any number:";
cin>>n;
09
12
cout<<"Square root:"<<square(n);
getch();
return 0;
}
int main()
{
clrscr();
cout<<sum(1)<<endl;
cout<<sum(1,2)<<endl;
cout<<sum(1,2,3)<<endl;
getch();
return 0;
}
int sum(int a, int b, int c)
{
return(a+b+c);
}
0
class a
{
int n1,n2;
public:
a()
{
}
n1=22;
n2=25;
09
12
void putdata()
{
cout<<"n1="<<n1<<endl;
cout<<"n2="<<n2<<endl;
}
};
22
int main()
{
clrscr();
a obj;
obj.putdata();
getch();
return 0;
}
class a
{
int num1,num2;
public:
a(int n1, int n2)
{
num1=n1;
num2=n2;
}
void display()
{
cout<<"Num1:"<<num1<<endl;
0
cout<<"Num2:"<<num2<<endl;
}
};
int main()
{
clrscr();
a obj(3,8);
obj.display();
getch();
return 0;
09
12
}
#include<iostream.h>
#include<conio.h>
class marksheet
{
int roll_no,m1,m2,m3,total,per;
char name[30],grade;
public:
void getdata();
};
void marksheet::getdata()
{
cout<<"Enter student roll no:";
cin>>roll_no;
cout<<"Enter student name:";
cin>>name;
cout<<"Enter student marks 1:";
cin>>m1;
cout<<"Enter student marks 2:";
cin>>m2;
cout<<"Enter student marks 3:";
cin>>m3;
total=m1+m2+m3;
per=(total)/3;
cout<<"Percentage:"<<per;
}
0
int main()
{
int i;
clrscr();
marksheet student[3];
for(i=0;i<3;i++)
{
}
09
cout<<"\n*****Details of student***** "<<i+1<<endl;
student[i].getdata();
12
getch();
return 0;
}
0
09
12
22