Slip27 C++

C++ Programming

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)
[Marks 15]

Solution

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class sales
{
 private:
char sname[20];
char pname[20];
int qty;
double target;
float com;
 public:
void accept();
void display();
void commission();
};
void sales:: accept()
{
  cout<<"Enter the saleman name:";
  gets(sname);
  cout<<"Enter the product:";
  gets(pname);
  cout<<"Enter the quantity:";
  cin>>qty;
  cout<<"Enter the target:";
  cin>>target;
}
void sales:: display()
{
  cout<<"\nSaleman name:"<<sname;
  cout<<"\nProduct:"<<pname;
  cout<<"\nQuantity:"<<qty;
  cout<<"\nTarget:"<<target;
  cout<<"\nCommission="<<com;
}
void sales:: commission()
{
 if(qty>target)
 {
  com=(25*qty)/100+(10*target)/100;
 }
 else if(qty==target)
 {
  com=(10*qty)/100;
 }
 else
 {
   com=0;
 }
}
void main()
{
  sales s[10];
  clrscr();
  int i,j,n;
  cout<<"Enter how many sales man:";
  cin>>n;
  for(i=0;i<n;i++)
  {
   s[i].accept();
  }
  for(i=0;i<n;i++)
  {
   s[i].commission();
  }
  for(i=0;i<n;i++)
  {
   s[i].display();
  }
getch();
}


Output

Enter the target:450
Enter the saleman name:Abhi
Enter the product:Shoes
Enter the quantity:350
Enter the target:325
Enter the saleman name:Ravi
Enter the product:Bags
Enter the quantity:500
Enter the target:475

Saleman name:Akshay
Product:Shirts
Quantity:500
Target:450
Commission=170
Saleman name:Abhi
Product:Shoes
Quantity:350
Target:325
Commission=119.5
Saleman name:Ravi
Product:Bags
Quantity:500
Target:475
Commission=172.5


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 [Marks 25]

Solution

#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<iostream.h>
class MyString
  {
  char *str;
public:
  void get()
{
  char t[80];
  cout<<"\nEnter String : ";
  fflush(stdin);
  gets(t);
  str=new char[strlen(t)+1];
  strcpy(str,t);
}
  void operator!();
  void operator[](int i)
{
  cout<<"\nChar Is : "<<str[i];
}
  void disp()
{
  cout<<"\n"<<str;
}
  };
void MyString :: operator!()
  {
int i;
for(i=0;str[i]!='\0';i++)
  {
if(str[i]>=65&&str[i]<=90)
  str[i]=str[i]+32;
else
  {
if(str[i]>=97&&str[i]<=122)
  str[i]=str[i]-32;
  }
  }
  }
void main()
{
MyString S;
clrscr();
S.get();
S.disp();
S[5];
!S;
S.disp();
getch();
}


Output

Enter String : abcdef pqrxyz

abcdef pqrxyz
Char Is : f
ABCDEF PQRXYZ
BCA Pratical Solution

My name is Vivek And I from Mumbai and Complete my Graduation Bca.my Age is 23 Years.

Post a Comment

Previous Post Next Post