CPP SLIP
CPP SLIP
Ans:
#include <iostream>
if(a>b)
return a;
else
return b;
int main()
int a;
cin>>a;
int b;
cin>>b;
}
Q1b] ) Create a C++ class MyFile with data members file pointer and filename. Write necessary member functions to
accept and display File. Overload the following operators:
//#include<conio.h>
#include<stdio.h>
#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<ctype.h>
#include <string.h>
class myfile
FILE * fp;
char fn [ MAXSIZE];
public:
myfile(char * fname)
strcpy(fn,fname);
void display();
};
void myfile::display()
fp-fopen(fn,"r");
char ch;
while((ch-fgetc(fp))!=EOF)
cout<<ch;
fclose(fp);
void myfile::operator ! ()
myfile f4("sy.txt");
char ch;
fp=fopen(fn,"r");
f4.fp-fopen(f4.fn,"w");
while((ch-fgetc(fp))!=EOF)
if(isupper(ch))
fputc(tolower(ch),f4.fp);
else if (islower(ch))
fputc(toupper(ch),f4.fp);
else
fputc(ch,f4.fp);
fclose(fp);
fclose(f4.fp);
remove("abc.txt");
rename("sy.txt", "abc.txt");
myfile f3("abc.txt");
fp-fopen(fn,"r");
f2.fp-fopen(f2.fn, "r");
f3.fp-fopen(f3.fn,"w");
char ch;
while((ch-fgetc(fp))!=EOF)
fputc(ch,f3.fp);
fclose(fp);
while((ch=fgetc(f2.fp))!=EOF)
fputc(ch,f3.fp);
fcloseall();
return f3;
int main()
myfilefl("xyz.txt");
myfile f2("lmn.txt");
myfile f3("abc.txt");
//clrscr();
cout<<" first file \n";
fl.display();
f2.display();
f3 =f1+f2;
f3.display();
!f3;
f3.display();
//getch();
return 0;
OUTPUT
Q2a]) Write a C++ program to find volume of cylinder, cone and sphere. (Use function overloading).
Ans:
#include<iostream>
#include<conio.h>
float vol(int,int);//cylinder
float vol(float,int);//cone
float vol(float);//sphere
int main()
float radius1;
cin>>radius;
cin>>height;
cin>>radius2;
cin>>height2;
cin>>radius1;
return 0;
return(3.14*radius*radius*height);
return(0.33*3.14*radius2*radius2*height2);
return((4*3.14*radius1*radius1*radius1)/3);
Output:-
Q2b] Write a C++ program to create a class Movie with data members M_Name, Release_Year, Director_Name and
Budget. (Use File Handling) Write necessary member functions to:
i. Accept details for 'n' Movies from user and store it in a file "Movie.txt".
#include<iostream>
#include<conio.h>
#include<fstream>
class Movie
public:
int year;
char mname[20];
char dname[15];
int budget;
public:
void accept()
cin>>mname;
cin>>year;
cin>>dname;
cin>> budget;
void display()
};
int main()
Movie m[5];
int n,i;
fstream file;
file.open("Movie.bet", ios::in|ios::out);
cin>>n;
for(i=0;i<n;i++)
m[i].accept();
file.write((char*)&m[i], sizeof(m[i]));
for(i=0;i<n; i++)
file.read((char*) &m[i],sizeof(m[i]));
m[i].display();
file.close();
getch();
OUTPUT
Q3a]Write a C++ program to interchange values of two integer numbers. (Use call by reference)
#include<iostream>
#include<conio.h>
class integer
public:
int x,y;
void getdata();
void display();
void(swap(int&,int&));
};
void integer::getdata()
cin>>x;
cin>>y;
void integer::display()
cout<<"\nDisplayvalues:-";
cout<<"x="<<x;
cout<<"\ny="<<y;
void integer::swap(int&p,int&q)
int temp;
temp=p;
p=q;
q=temp;
cout<<"\n\nAfterswaping\n\n";
cout<<"\nx="<<y;
cout<<"\ny="<<x;
int main()
int x,y;
integer i;
i.getdata();
i.display();
i.swap(x,y);
getch();
OUTPUT
Q3b]) Write a C++ program to accept 'n' numbers from user through Command Line Argument.
Store all Even and Odd numbers in file "Even.txt" and "Odd.txt" respectively.
#include<iostream>
#include<fstream>
#include<stdlib.h>
#define MAX 10
int main()
int num[MAX],n;
cin>>n;
for(int i=0;i<n;i++)
cin>>num[i];
ofstream fout1,fout2;
fout1.open("Even.txt");
if(fout1.fail())
exit(1);
fout2.open("Odd.txt");
if(fout2.fail())
exit(1);
for(int i=0;i<n;i++)
if(num[i]%2==0)
fout1<<num[i]<<"";
else
fout2<<num[i]<<"";
fout1.close();
fout2.close();
fin1.open("Odd.txt");
if(fin1.fail())
exit(1);
fin2.open("Even.txt");
if(fin2.fail())
exit(1);
cout<<"Contents of Odd.txt\n";
do
char ch;
fin1.get(ch);
cout<<ch<<"";
while(fin1);
fin1.close();
cout<<"\nContents of Even.txt\n";
do
char ch;
fin2.get(ch);
cout<<ch<<"";
}
while(fin2);
fin2.close();
cout<<"\n";
system("pause");
return 0;
OUTPUT
Q4a]A C++ program to accept Worker information Worker Name, No_ofHours_worked, Pay_Rate and Salary.
Write necessary functions to calculate and display the salary of Worker. (Use default value for Pay_Rate)
#include<iostream>
#include<conio.h>
class worker
public:
char worker_name[20];
cout<<"\n________________________________";
cin>>worker_name;
cin>>hrworked;
salary=pay_rate*hrworked;
cout<<"\n________________________________";
cout<<"\n________________________________";
};
int main()
worker w;
w.calsalary();
getch();
OUTPUT
Q4b]Write a C++ program to create a base class Employee (Emp-code, name, salary). Derive two classes as
Fulltime (daily_wages, number_of_days) and Parttime(number_of working hours, hourly wages).
3. Display the details of employee having maximum salary for both types of employees
#include<iostream>
class emp
public:
int empno;
char empname[30];
public:
void get()
cin>>empno;
cin>>empname;
};
public:
float daily_rate;
int days;
int salary;
public:
void getdata()
{
cout<<"\n Enter Daily Rate :";
cin>>daily_rate;
cin>>days;
void cal()
salary=daily_rate*days;
void show()
cout<<"\n ----------------------------------\n";
cout<<"\n ----------------------------------\n";
};
public:
int hourly_rate;
int working_hours;
int salary1;
public:
void get1()
cin>>hourly_rate;
cin>>working_hours;
}
void cal1()
salary1=hourly_rate*working_hours;
void show1()
cout<<"\n ----------------------------------\n";
cout<<"\n ----------------------------------\n";
};
int main()
int constcnt=5;
int var=0;
int var1=0;
fulltime f1[cnt];
parttime p1[cnt];
int x,i;
do
cout<<"\n";
cout<<"\n 4.Quit";
cin>>x;
switch(x)
case 1:
int y;
cin>>y;
switch(y)
case 1:
f1[var].get();
f1[var].getdata();
f1[var].cal();
var++;
break;
case 2:
p1[var1].get();
p1[var1].get1();
p1[var1].cal1();
var1++;
break;
break;
case 2:
f1[i].show();
p1[i].show1();
break;
case 3:
int a;
cin>>a;
if (f1[i].empno==a)
f1[i].show();
if(p1[i].empno==a)
p1[i].show1();
} while(x!=4);
return 0;
OUTPUT
Q5a]a) Consider the following C++ class class Point int x,y; public: void setpoint(int, int);// To set the values of x
and y co-ordinate. void showpoint();// To display co-ordinate of a point P in format (x, y).
#include<iostream>
class point
int x,y;
public:
x=p;
y=q;
void showpoint()
};
int main()
point a;
a.setpoint(9,19);
a.showpoint();
return(0);
OUTPUT
Q5b]
Create a C++ base class Shape. Derive three different classes Circle, Sphere and Cylinder from shape class. Write a
C++ program to calculate area of Circle, Sphere and Cylinder. (Use pure virtual function).
#include<iostream>
#include<conio.h>
#include<stdlib.h>
class shape
public:
};
public:
int r;
void getc()
cin>>r;
void area();
};
public:
int r1;
void getr()
cin>>r1;
void area();
};
public:
int r2,h;
void gett()
cin>>r2;
cin>>h;
void area();
};
void Circle::area()
cout<<(3.14*r*r);
void Sphere::area()
cout<<(4*3.14*r1*r1);
void Cylinder::area()
int d=h+r2;
cout<<d;
cout<<(2*3.14*r2*d);
int main()
{
int ch;
Circle c;
Sphere S;
Cylinder t;
do
cout<<"\n 4. Exit";
cin>>ch;
switch(ch)
case 1:
c.getc();
c.area();
cout<<"\n_____________________________________";
break;
case 2:
S.getr();
S.area();
cout<<"\n_____________________________________";
break;
case 3:
t.gett();
t.area();
cout<<"\n_____________________________________";
break;
case 4:
exit(0);
}while(ch!=4);
getch();
};
OUTPUT
Q6a]) Write a C++ program to create two Classes Square and Rectangle. Compare area of both the shapes using
friend function. Accept appropriate data members for both the classes
#include<iostream>
#include<conio.h>
class Square
int side;
public:
Square(int s)
side=s;
};
class Rectangle
int length;
int breadth;
public:
int getArea()
return length*breadth;
void shape(Square a)
length = a.side;
breadth = a.side;
};
int main()
{
Square square(5);
Rectangle rectangle;
rectangle.shape(square);
cout<<rectangle.getArea();
return 0;
getch();
OUTPUT
Q6b]b) Create a C++ class class Matrix { int * *p int r, c; public: //member functions }
#include<iostream>
class MATRIX
int a[5][5];
int row,col;
row=x;
col=y;
void read();
void display();
void transpose();
};
void MATRIX::read()
for(int i=0;i<row;i++)
void MATRIX::display()
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
cout<<a[i][j]<<"";
cout<<"\n";
void MATRIX::transpose()
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
cout<<a[j][i]<<"";
cout<<"\n";
int main()
int m,n;
MATRIX obj1(m,n);
obj1.read();
cout<<"Matrix is…\n";
obj1.display();
obj1.transpose();
OUTPUT
Q7a]Write a C++ program using class with data member char str[50] and function replace (char chl, char ch2) every
occurrence of chl in str should be replaced with ch2 and return number of replacement it makes use default value
for char ch2. (Use ch2 as Default Argument)
#include<conio.h>
#include<iostream>
#include<string.h>
class mystr
};
while(str!='\0')
if(* str==c1)
*str==c2;
n++;
str=str-i;
return n;
int main()
mystr m;
char *str,c1,c2;
cout<<"enter string";
cin>>str;
cin>>a;
cout<<"number of replacement="<<m.replace(str,c1,c2);
return 0;
OUTPUT
Q7b]b) Create a C+ + class Vector with data members size & pointer to integer. The size of the vector varies so
the memory should be allocated dynamically. Perform following operations: Accept a vector Display a vector in the
format (10, 20, 30,....) iii. Calculate union of two vectors. (use parameterized constructor & copy
#include<iostream>
class vector
int *a ,*b;
int n ,n1;
public:
int create()
int i,j;
cin>>n;
a=new int[n];
for(i=0;i<n;i++)
cin>>a[i];
cin>>n1;
b=new int[n1];
for(j=0;j<n1;j++)
cin>>b[j];
}
int display()
int i,j;
for(i=0;i<n-1;i++);
cout<<a[i]<<",";
cout<<a[n-1]<<")";
for(j=0;j<n1-1;j++);
cout<<b[j]<<",";
cout<<b[n1-1]<<")";
};
int main()
vector v;
int ch;
do{
cout<<"\nEnter Choice:";
cin>>ch;
switch(ch)
case 1:
v.create();
break;
case 2:
v.display();
break;
case 3:
vector<int>v(10);
vector<int>::iterator st;
sort(a[i],a[i]+3);
sort(b[j],b[j]+3);
st=set_union(a[i],a[i]+3,b[j],b[j]+3,v.begin());
v.resize(st-v.begin());
for(st=v.begin();st!=v.end();++st)
cout<<*st<<"";
break;
}while(ch!=3);
OUTPUT
8a) Write a C++ program to create a class Number, which contain static data member 'ent' and member function
'Display()'. Display() should print number of times display operation is performed irrespective of the object
responsible for calling Display() .
#include<iostream>
#include<conio.h>
class Number
public:
cnt++;
};
int Number::cnt;
int main()
Number s1,s2,s3,s4;
s1.display();
s2.display();
s3.display();
s4.display();
getch();
OUTPUT
8b) Create a C++ class Person with data members Person_name, Mobile number, Age, City. Write necessary
member functions for the following:
long phoneno;
public:
void get_data()
cin>>name;
cin>>phoneno;
cin>>city;
void display_data()
if(strcmp(name,x)==0)
void searchpno(int x)
if((phoneno==x)==1)
if(strcmp(city,c)==0)
display_data();
};
int main()
Person t[30],n[20],c[20];
int num,ch,i,pno;
char cont,cty[30],name1[30];
do{
cin>>ch;
switch(ch)
cin>>num;
for(i=0;i<num;i++)
t[i].get_data();
for(i=0;i<num;i++)
{
t[i].display_data();
break;
case 2:
cin>>name1;
for(i=0;i<num;i++)
t[i].searchname(name1);
break;
case 3:
cin>>pno;
for(i=0;i<num;i++)
t[i].searchpno(pno);
break;
case 4:
cin>>cty;
for(i=0;i<num;i++)
t[i].searchcity(cty);
break;
cin>>cont;
}while(cont=='Y'||cont=='y');
}}}
OUTPUT
9a) Consider the following C++ class class Person char Name [20]; charAddr [30] float Salary; float tax_amount;
public: // member functions
#include<iostream>
#include<conio.h>
class person
char name[20];
char addr[20];
float sal,tax;
public:
void get()
cin>>name;
cin>>addr;
cin>>sal;
void put()
cout<<"_____________________________________\n";
cout<<"_____________________________________\n";
cout<<"Name:\tAddress:\tSalary:\tTax:\n";
cout<<name<<"\t"<<addr<<"\t"<<sal<<"\t"<<tax<<endl;
void cal_tax()
{
if(sal<=20000)
tax=0;
else if(sal>=20000||sal<=40000)
tax=(sal*5)/100;
else if(sal>40000)
tax=(sal*10)/100;
};
int main()
person p;
p.get();
p.cal_tax();
p.put();
getch();
OUTPUT
9b) Create a C++ class Time with data members Hours, Minutes and Seconds. Write necessary member functions
for the following: (Use Objects as arguments)
i. To accept a time.
iii. To find difference between two time and display it in format hh:mm:ss.
10a) Write a C++ program to create a class Account with data members Acc_number, Acc_type and Balance. Write
member functions to accept and display 'n' account details. (Use dynamic memory allocation
#include<iostream>
#include<conio.h>
#include<stdlib.h>
class Account
public:
int Acc_no,Balance;
char Acc_type[30];
public:
Account() { cout<<"Constructor"<<endl;}
~Account() { cout<<"Destructor"<<endl;}
void get_data()
cin>>Acc_no;
cin>>Acc_type;
cin>>Balance;
void display_data()
cout<<"\t"<<Acc_no<<"\t"<<"\t"<<Acc_type<<"\t"<<Balance;
};
int main()
{
int i,num;
Account*a=new Account[4];
delete[]a;
cin>>num;
for(i=0;i<num;i++)
a[i].get_data();
for(i=0;i<num;i++)
a[i].display_data();
return 0;
OUTPUT
Q10b]b) Create a C++ class City with data members City_code, City_name, population. Write necessary member
#include<stdio.h>
#include<conio.h>
#include<iostream>
class MyArray
int size,*ptr,*p;
int sum=0;
public:
MyArray(int no)
size=no;
ptr=new int[size];
for(int i=0;i<size;i++)
cout<<"enter elements";
cin>>ptr[i];
sum = sum+ptr[i];
void display()
cout<<"elements are";
for(int i=0;i<size;i++)
cout<<ptr[i]<<"\t";
}
void sum()
int arr[10];
int i;
int sum=0;
for(i=0;i<10;i++)
cin>>arr[i];
for(i=0;i<10;i++)
cout<<arr[i]<<"";
MyArray()
delete ptr;
};
void main()
int n;
cout<<"enter size";
cin>>n;
MyArray d(n);
d.display();
d.sum();
getch();
}
OUTPUT
Q11b]b) Create a base class Student with data members Roll No, Name. Derives two classes from it,
Theory with data members MI, M2, M3, M4 and class Practical with data members PI, P2. Class
Result(Total_Marks, Percentage, Grade) inherits both Theory and Practical classes. (Use concept of
#include<conio.h>
#include<string.h>
#include<conio.h>
#include<iostream>
class student
protected:
int rno;
char name[20];
public:
void getdetails();
};
protected:
public:
void getmarks();
};
protected:
int p1,p2;
public:
void getpractical();
};
int total_marks;
float per;
public:
void calc();
void display();
};
void student::getdetails()
cin>>rno>>name;
void Theory::getmarks()
cin>>mark1>>mark2>>mark3>>mark4;
void Practical::getpractical()
cin>>p1>>p2;
void result::calc()
int i;
total_marks=mark1+mark2+mark3+mark4+p1+p2;
per=total_marks/(float)6;
if(per<50)
strcpy(grade,"C");
else
if(per<60)
strcpy(grade,"B");
else
if( per<75)
strcpy(grade,"A");
else
strcpy(grade,"A+");
result rt;
if(r1.total_marks>r2.total_marks)
rt=r1;
r1=r2;
r2=rt;
void result::display()
int main()
int n,i,ch,j;
result r[20];
do
{
cin>>ch;
switch(ch)
case 1:
cin>>n;
for(i=0;i<n;i++)
r[i].getdetails();
r[i].getmarks();
r[i].getpractical();
break;
case 2:
for(i=0;1<n;i++)
r[i].calc();
break;
case 3:
for(i=0;1<n;i++)
for(j=i+1;j<n;j++)
r[i].sort(r[i],r[j]);
r[i].display();
break;
} while(ch<=3);
getch();
return 0;
}
OUTPUT
Q12a]a) Write a C++ program to create a class Date with data members day, month, and year. Use default and
parameterized constructor to initialize date and display date in dd-Mon-yyyy format. (Example: Input:
#include<conio.h>
#include<iostream>
class date
int dd,mm,yyyy;
public:
dd=d;
mm=m;
yyyy=y;
void disp()
if(mm>12)
else
cout<<"Input :"<<dd<<"/"<<mm<<"/"<<yyyy<<endl;
if(mm==1)
cout<<"Output :"<<dd<<"/"<<"jan"<<"/"<<yyyy;
else if(mm==2)
cout<<"Output :"<<dd<<"/"<<"Feb"<<"/"<<yyyy;
else if(mm==3)
{
cout<<"Output :"<<dd<<"/"<<"mar"<<"/"<<yyyy;
else if(mm==4)
cout<<"Output :"<<dd<<"/"<<"apr"<<"/"<<yyyy;
else if(mm==5)
cout<<"Output :"<<dd<<"/"<<"may"<<"/"<<yyyy;
else if(mm==6)
cout<<"Output :"<<dd<<"/"<<"jun"<<"/"<<yyyy;
else if(mm==7)
cout<<"Output :"<<dd<<"/"<<"july"<<"/"<<yyyy;
else if(mm==8)
cout<<"Output :"<<dd<<"/"<<"Aug"<<"/"<<yyyy;
else if(mm==9)
cout<<"Output :"<<dd<<"/"<<"sep"<<"/"<<yyyy;
else if(mm==10)
cout<<"Output :"<<dd<<"/"<<"oct"<<"/"<<yyyy;
else if(mm==11)
cout<<"Output :"<<dd<<"/"<<"Nov"<<"/"<<yyyy;
}
else if(mm==12)
cout<<"Output :"<<dd<<"/"<<"Dec"<<"/"<<yyyy;
};
int main()
int d,m,y;
cin>>d;
cin>>m;
cin>>y;
d1.disp();
getch();
return(0);
OUTPUT
Q12B) write a c++ class wait and data members kilogram gram write a c++ program using operator overloading to
perform following function
i) To accept weight
#include<iostream>
#include<conio.h>
class Weight
int kilogram,gram;
public:
void getdata()
cin>>kilogram;
cin>>gram;
void display()
cout<<kilogram<<"."<<gram;
void display2()
cout<<kilogram<<"."<<gram;
Weight t;
t.kilogram=d.kilogram+kilogram;
t.gram=d.gram+gram;
return t;
if(kilogram==d.kilogram || gram==d.gram)
return 1;
else
return 0;
};
int main()
Weight c1,c2,c3,c4,c5
c1.getdata();
C2.getdata();
c3=c1+=c2;
c3.display();
c4.getdata();
c5.getdata();
if(c4==c5)
cout<<"\n";
c4.display2();
c5.display2();
else
cout<<"\n";
c5.display2();
c4.display2();
getch();
OUTPUT
13a]Write a C++ program to create a class Product with data members Product id, Product_Name, Qty,
Price. Write member functions to accept and display Product information also display number of objects
created for Product class. (Use Static data member and Static member function
#include<iostream>
class Item
int code,price;
public:
void accept()
cin>>code>>price;
for(int i=0;i<5;i++)
cout<<"\n\n "<<i+1;
int s=0;
for(int i=0;i<5;i++)
s=a[i].price+s;
};
int main()
Item e[5];
for(int i=0;i<5;i++)
cout<<"\n\n "<<i+1;
e[i].accept();
e[1].display(e);
e[1].sum(e);
return 0;
OUTPUT
13b) Create a C++ class Cuboid with data members length, breadth, and height. Write necessary member functions
for the following:
iv. float surface_area( ) to calculate and return the surface area of cuboid.
#include<stdio.h>
#include<conio.h>
#include<iostream>
class Cuboid
float a,b,c;
public:
void getdata()
cin>>a;
cin>>b;
cin>>c;
void setdata()
cout<<a<<b<<c;
{
cout<<"\n The surface area of cuboid =\t"<<2*a*b+2*a*c+2*b*c;
};
int main()
Cuboid c;
c.getdata();
c.volume();
c.surface_area();
getch();
OUTPUT
14a]) Write a C++ program to accept radius of a Circle. Calculate and display diameter, circumference as well as
area of a Circle. (Use Inline function)
#include <iostream>
return (r*2);
return(3.14*r*r);
return(3.14*2*r);
int main()
float radius;
cin>>radius;
cout<<"\nDiameter of Circle:"<<dimeter(radius);
cout<<"\nArea of Circle:"<<circlearea(radius);
cout<<"\nCircumference of Circle:"<<circumference(radius);
return 0;
OUTPUT
Q14b]) Create a C++ class MyString with data members a character pointer and str_length. (Use new and
delete operator). Write a C++ program using operator overloading to perform following operation:
To reverse the case of each alphabet from a given string 11. < To compare length of two strings.+
#include<string.h>
#include<iostream>
#include<conio.h>
class mystring
public:
int n;
int i,c;
void accept()
cin>>n;
cin>>p;
void disp()
for(i=0;i<n;i++)
if(p[i]>64&&p[i]<91)
p[i]=p[i]+32;
}
else
p[i]=p[i]-32;
int e;
char m;
e=l;
for(i=0;i<c;i++)
if(e-1==i)
};
int main()
do{
cin>>ch;
switch(ch)
case 1: mystring m;
m.accept();break;
case 2: m.disp();break;
case 3: !m;break;
cin>>e;
m[e];break;
}while(ch!=5);
OUTPUT
Q15a]Create a C++ class Fraction with data members Numerator and Denominator. Write a C++ program to
calculate and display sum of two fractions. (Use Constructor)
#include<iostream>
#include<conio.h>
class fraction
int num;
int deno;
public:
fraction()
fraction(int a,int b)
num=a;
deno=b;
void display()
cout<<"\nFraction is:"<<num<<"/"<<deno;
};
fraction a;
a.num=p.num + q.num;
a.deno=p.deno + p.deno;
return a;
}
int main()
fraction f1(2,1);
fraction f2(3,2);
fraction f3;
f1.display();
f2.display();
f3=f1+f2;
f3.display();
getch();
OUTPUT
Q15b]Write a C++ class Seller (S_Name, Product name, Sales_Quantity, Target_Quantity, Month,Commission).
Each salesman deals with a separate product and is assigned a target for a month. At the end of the month his
monthly sales is compared with target and commission is calculated as follows: If Sales_Quantity>Target_Quantity
then commission is 25% of extra sales made + 10% of target. If Sales_Quantity = Target_Quantity then commission
is 10% of target. Otherwise commission is zero.
Display salesman information along with commission obtained. (Use array of objects)
#include<iostream>
#include<conio.h>
class sales
char sname[20],pname[20];
int squantity,target,month;
float commission;
public:
void get()
cin>>sname;
cin>>pname;
cin>>squantity;
cout<<"\nEnter target:\t";
cin>>target;
cout<<"\nEnter month:\t";
cin>>month;
void
put()
cout<<"\nSalesman name:\t"<<sname;
cout<<"\nProduct name:\t"<<pname;
cout<<"\nSales quantity:\t"<<squantity;
cout<<"\nTarget:\t"<<target;
cout<<"\nMonth:\t"<<month;
commission=0;
if(squantity>target)
commission=commission+((squantity-target)*0.25)+(target*0.10);
else
if(target=squantity)
commission=commission+(target*0.10);
else
commission=0;
cout<<"\nCommission:\t"<<commission;
};
int main()
sales sman[10];
int i,n;
cin>>n;
for(i=0;i<n;i++)
sman[i].get();
for(i=0;i<n;i++)
sman[i].put();
getch();
return 0;
}
OUTPUT