slip 27


/* Slip no : 27_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<conio.h>
#include<iostream.h>
class sales
{
                char sname[20],pname[20];
                int s_qty,t;
                float com;
                public :
                void getdata()
                {
                                cout<<"\n Enter Salesmam_Name  :  ";
                                cin>>sname;
                                cout<<"\n Enter Product Name  :  ";
                                cin>>pname;
                                cout<<"\n Enter sales Quantity : ";
                                cin>>s_qty;
                                cout<<"\n Enter target : ";
                                cin>>t;
                }
                void cal()
                {
                                if(s_qty>t)
                                                com=(s_qty+(s_qty*0.25))+(t+(t*0.10));
                                else if(s_qty==t)
                                                com=t+(t*0.10);
                                else
                                                com=0;

                }
                void display()
                {
                                cout<<"\n Salesmam_Name  :  "<<sname;
                                cout<<"\n Product Name  :  "<<pname;
                                cout<<"\n Sales Quantity : "<<s_qty;
                                cout<<"\n Target : "<<t;
                                cout<<"\n Monthly comission is : "<<com;
                                cout<<"\n ========================================";
                }


};

void main()
{
                sales s[10];int i,n;
                cout<<"\n Enter how many Salesman : ";
                cin>>n;
                for(i=0;i<n;i++)
                {              s[i].getdata();
                                s[i].cal();
                }

                for(i=0;i<n;i++)
                {              s[i].display();

                }
                getch();

}





/* Slip no : 27_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

slip 27 slip 27 Reviewed by Dinesh Varal on January 31, 2018 Rating: 5

No comments:

Powered by Blogger.