Slip27
Q.1) Write a class sales (Salesmam_Name,
Product_name, Sales_Quantity, Target). 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 then commission is 25% of
extra sales made + 10% of target
·
If Sales_Quantity ==target then commission is 10% of
target.
·
Otherwise commission is zero
Display the
salesman information along with commission obtained. (Use array of objects)
#include<iostream.h>
#include<conio.h>
class
sales
{
char
sname[20],pname[20];
int
squantity,target;
float
commission;
public:
void
get()
{
cout<<"Enter
salesman name:\t";
cin>>sname;
//clrscr();
cout<<"\nEnter
product name:\t";
cin>>pname;
//clrscr();
cout<<"\nEnter
sales quantity:\t";
cin>>squantity;
//clrscr();
cout<<"\nEnter
target:\t";
cin>>target;
//clrscr();
}
void
put()
{
cout<<"\nSalesman
name:\t"<<sname;
cout<<"\nProduct
name:\t"<<pname;
cout<<"\nSales
quantity:\t"<<squantity;
cout<<"\nTarget:\t"<<target;
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;
}
};
void main(){
sales sman[10];
int i,n;
clrscr();
cout<<"\n Enter how many Salesman : ";
cin>>n;
for(i=0;i<n;i++)
{
sman[i].get();
}
for(i=0;i<n;i++)
{
sman[i].put();
}
getch();
}
Q.2) Create a class MyString which
contains a character pointer (Use new and delete operator). Write a C++ program
to overload following operators:
! To change the case of each alphabet from
given string
[ ]
To print a character present at specified index
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
class mystring
{
char *str;
int len;
public:
mystring()
{
}
mystring(char s[])
{
len=strlen(s);
str=new char[len+1];
strcpy(str,s);
}
void display()
{
cout<<"\nstring = "<<str;
}
void operator !()
{
int i;
for(i=0;str[i]!='\0';i++)
{
if(islower(str[i]))
{
str[i]=toupper(str[i]);
}
else
{
str[i]=tolower(str[i]);
}
}
}
char operator [](int &index)
{
if(index>0
&& index<len)
return str[index];
else
return '_';
}
};
void main()
{
clrscr();
int i;
char str[30];
cout<<"\n Enter string : ";
cin>>str;
mystring m(str);
m.display();
!m;
m.display();
cout<<"\n Enter index : ";
cin>>i;
char ch = m[i];
if(ch!='_')
cout<<"\n Chracter at given position
"<<ch;
else
cout<<"\n Invalid index ";
getch();
}