0% found this document useful (0 votes)
846 views

C++ Lab Report

This C++ program implements classes and objects to manage restaurant details in a mall. It allows the user to enter details of a restaurant such as name, owner, square footage, advance paid etc. and calculates the rent and advance to be paid. The program also allows entering details of accessories sold in the restaurant like name, code, price, quantity and calculates the total cost. It uses classes, objects, functions and validation checks.

Uploaded by

Shophi Philip
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
846 views

C++ Lab Report

This C++ program implements classes and objects to manage restaurant details in a mall. It allows the user to enter details of a restaurant such as name, owner, square footage, advance paid etc. and calculates the rent and advance to be paid. The program also allows entering details of accessories sold in the restaurant like name, code, price, quantity and calculates the total cost. It uses classes, objects, functions and validation checks.

Uploaded by

Shophi Philip
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 69

C++ Lab

Program Number
Program Name
Date implemented

: 1
: To implement Classes and Objects
: November 19, 2012

Domain name: Mall Management


In this program, the details regarding the restaurants in a mall are entered, and the
different assets given to them are calculated using Classes and Objects.
/***************************************************************
* Author: Shophi Philip
***************************************************************/
#include<iostream.h>
#include<conio.h>
#include<string.h>
class restaurant
{
int num;
float price,sqft,val,adv,advpaid,tobepaid;
char name[30],code[20],restname[30],owner[30];
char pricech[20],numch[20],sqftch[20],advch[20],advpaidch[20];
public:
void details(void);
/* Function calculates price of the commodity and returns the value*/
float calc()
{
return (float)price*num;
}
/* Function calculates the rent of the shop based on the square feet*/
float rentcalc()
{
if(sqft>10000)
val=(float)sqft*175;
else if(sqft<=10000 && sqft>5000)
val=(float)sqft*150;
else if(sqft<=5000 && sqft>2500)
val=(float)sqft*100;
else if(sqft<=2500 && sqft>1000)
val=(float)sqft*75;
else
val=(float)sqft*50;
return val;
}
/* Function calculates advance to be paid by the restaurant*/
float calctobepaid()
{
if(advpaid>adv)
{
cout<<"\n\t\t\tWrong input for advance paid";
return 0;
}
else
return (float)adv-advpaid;
}
void getdata(void);
Department of Computer Science, Christ University

C++ Lab

void getrent(void);
void display(void);
void displaydetails(void);
};
/* Function used to validate string values*/
int isstring(char s[])
{
int i=0;
while(s[i])
{
if(!((s[i]>=65 && s[i]<92) || (s[i]>=97 && s[i]<123) || s[i]==32))
{
return 0;
}
i++;
}
return 1;
}
/* Function used to validate integer values*/
int isint(char s[])
{
int i=0;
while(s[i])
{
if(!((s[i]>=48 && s[i]<=57)))
{
return 0;
}
i++;
}
return 1;
}
/* Function used to validate float values*/
int isfloat(char s[])
{
int i=0,f=0;
while(s[i])
{
if(!((s[i]>=48 && s[i]<=57)))
{
if(f==0&&s[i]=='.')
{
f=1;
i++;
continue;
}
return 0;
}
i++;
}
return 1;
}
/* Function to enter details of the restaurant*/
void restaurant :: details(void)
{
restname:cout<<"\n\nENTER RESTAURANT NAME
cin>>restname;
if(!isstring(restname))
Department of Computer Science, Christ University

: ";

C++ Lab

{ cout<<"Enter a string!!!\n";
goto restname;}
owner:cout<<"\nENTER MANAGER NAME
cin>>owner;
if(!isstring(owner))
{ cout<<"Enter a string!!!\n";
goto owner;
}
}
/* Function to enter details of the restaurant*/
void restaurant :: getrent(void)
{
sqft: cout<<"\nENTER SQUARE FEET
: ";
cin>>sqftch;
if(!isfloat(sqftch))
{ printf("Enter a floating number!!!\n");
goto sqft;}
sqft=atof(sqftch);
adv: cout<<"\nADVANCE TO BE PAID
:";
cin>>advch;
if(!isfloat(advch))
{ printf("Enter a floating number!!!\n");
goto adv;}
adv=atof(advch);
advpaid: cout<<"\nADVANCE PAID
:";
cin>>advpaidch;
if(!isfloat(advpaidch))
{ printf("Enter a floating number!!!\n");
goto advpaid;}
advpaid=atof(advpaidch)
}
/* Function to enter details of the commodities*/
void restaurant :: getdata(void)
{
name:
cout<<"\n\n\nENTER ACCESSORY
: ";
fflush(stdin);
cin>>name;
if(!isstring(name))
{ cout<<"Enter a string!!!\n";
goto name;}
cout<<"\nENTER CODE
: ";
cin>>code;
price:
cout<<"\nENTER PRICE
: ";
cin>>pricech;
if(!isfloat(pricech))
{ printf("Enter a floating number!!!\n");
goto price;}
price=atof(pricech);
do
{
cout<<"\nENTER QUANTITY
: ";
cin>>numch;
if(isint(numch)==0)
printf("\n Enter an integer!!!");
}while(isint(numch)==0);
num=atoi(numch);
}

Department of Computer Science, Christ University

: ";

C++ Lab

/* Function displays the details of the commodities*/


void restaurant :: display(void)
{
cout<<"\n\nITEM DETAILS\n";
cout<<"\n\nName : "<<name;
cout<<"\n\nCode : "<<code;
cout<<"\n\nPrice : "<<price;
cout<<"\n\nQuantity : "<<num;
}
/* Function displays the details of the restaurant*/
void restaurant :: displaydetails(void)
{
cout<<endl<<"-------------------------------------------------------------------------------";
cout<<"\n\n\t\t\t
RESTAURANT DETAILS\n";
cout<<endl<<"-------------------------------------------------------------------------------";
cout<<"\n\n\t\t\tRestaurant Name : "<<restname;
cout<<"\n\n\t\t\tOwner Name
: "<<owner;
cout<<"\n\n\t\t\tSpace Available :"<<sqft;
cout<<"\n\n\t\t\tAdvance to be paid : "<<adv;
}
int main()
{
char ch;
cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@
*@*@*@*@*@*@*@*@*@*@*@*@*@";
printf("\n\n
M A L L M A N A G E M E N T \n\n");
cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@
*@*@*@*@*@*@*@*@*@*@*@*@*@";
cout<<endl<<endl<<endl;
cout<<"********************** R E S T A U R A N T D E T A I L S *********************";
restaurant r;
r.details();
r.getrent();
r.displaydetails();
cout<<endl<<"\n\t\t\tTotal amount to be debited : "<<r.calctobepaid();
cout<<endl<<endl<<"\n\t\t\tRent to be paid : "<<r.rentcalc();
do
{
r.getdata();
r.display();
cout<<endl<<endl<<"Total Cost of this item : "<<r.calc();
cout<<endl<<"Continue : ";
cin>>ch;
}while(ch=='y'||ch=='y');
cout<<endl<<"\t\tT H A N K Y O U";
getch();
return 0;
}

Department of Computer Science, Christ University

C++ Lab

OUTPUT:

Department of Computer Science, Christ University

C++ Lab

Program Number
Program Name
Date implemented

: 2
: To implement Constuctors and Destructors with array of
objects
: November 29, 2012

In this program,details about the shop and its employees are entered and the list of the
employees can be viewed.
/***************************************************************
* Author: Shophi Philip
***************************************************************/
#include<iostream.h>
#include<conio.h>
#include <string>
#include <iomanip>
using namespace std;
class shop
{
private:
int id;
int year;
char name[30];
char owner[30];
float rent;
char idch[20],rentch[20],yearch[20];
public:
shop()
{
cout<<"\n M A L L M A N A G E M E N T \n\n");
}
shop(int i,char n[],char o[],double r)
{
id=i;
strcpy(name,n);
strcpy(owner,o);
rent=r;
}
shop(shop &s)
{
year=s.year;
cout<<endl<<endl<<"Number of months : "<<year;
cout<<endl<<endl<<"Advance paid : "<<s.calc();
}
/* Function calculates the advance for the shop*/
float calc()
{
return (float)year*rent;
}
void getdata(void);
void display(void);
~shop()
{
cout<<endl<<"Shop id "<<id<<" deleted";}};
Department of Computer Science, Christ University

C++ Lab

class Employee {
string employeeName;
string employeeTitle;
int employeeAge;
long employeeSalary;
public:
void get_data(string, string, int, long);
void data_analysis();
void display_employee_list();
void display_stats();
char eagech[20],esalarych[20];
};
/* Function to enter the employee details*/
void Employee::get_data(string ename, string etitle, int eage, long esalary)
{
employeeName = ename;
employeeTitle = etitle;
employeeAge = eage;
employeeSalary = esalary;
}
/* Function displays the employee details*/
void Employee::display_employee_list()
{
cout<<employeeName << setw(20) << employeeTitle <<setw(19)<<employeeAge
<<setw(21)<<employeeSalary<<endl;
}
/* Function used to validate string values*/
int isstring(char s[])
{
int i=0;
while(s[i])
{
if(!((s[i]>=65 && s[i]<92) || (s[i]>=97 && s[i]<123) || s[i]==32))
{
return 0;
}
i++;
}
return 1;
}
/* Function used to validate ineger values*/
int isint(char s[])
{
int i=0;
while(s[i])
{
if(!((s[i]>=48 && s[i]<=57)))
{
return 0;
}
i++;
}
return 1;
}

Department of Computer Science, Christ University

C++ Lab

/* Function used to validate float values*/


int isfloat(char s[])
{
int i=0,f=0;
while(s[i])
{
if(!((s[i]>=48 && s[i]<=57)))
{
if(f==0&&s[i]=='.')
{
f=1;
i++;
continue;
}
return 0;
}
i++;
}
return 1;
}
/* Function to enter the shop details*/
void shop :: getdata(void)
{
name:
cout<<"\n\n\nEnter Name
: ";
fflush(stdin);
cin>>name;
if(!isstring(name))
{ cout<<"Invalid Name : Try Again\n";
goto name;}
owner: cout<<"\n\n\nEnter Owner Name
: ";
cin>>owner;
if(!isstring(owner))
{ cout<<"Invalid Name : Try Again\n";
goto owner;}
price:
cout<<"\n\n\nEnter Rent
: ";
cin>>rentch;
if(!isfloat(rentch))
{ printf("Invalid Amount : Try Again\n");
goto price;}
rent=atof(rentch);
do{
cout<<"\n\n\nEnter id
: ";
cin>>idch;
if(isint(idch)==0)
printf("\n WARNING: ERROR IN INPUT, TRY AGAIN !!!");
}while(isint(idch)==0);
id=atoi(idch);
do
{
cout<<"\n\n\nEnter months on contract : ";
cin>>yearch;
if(isint(yearch)==0)
printf("\n WARNING: ERROR IN INPUT, TRY AGAIN !!!");
}while(isint(yearch)==0);
year=atoi(yearch);
}
Department of Computer Science, Christ University

C++ Lab

/* Function displays the shop details*/


void shop :: display(void)
{
cout<<"\n\nSHOP DETAILS\n";
cout<<"\n\nName
: "<<name;
cout<<"\n\nCode
: "<<id;
cout<<"\n\nOwner
: "<<owner;
cout<<"\n\nRent
: "<<rent;
}
int main()
{
int cho;
Employee employees[100];
int n = 0;
string ename, etitle;
int eage;
long esalary;
char again;
cout<<endl<<endl<<endl;
shop s1;
s1.getdata();
s1.display();
shop s2(s1);
do {
cout <<endl<<"\nEnter employee name
: ";
fflush(stdin);
cin>>ename;
cout << endl;
cout <<"\nEnter employee title : ";
fflush(stdin);
cin>>etitle;
cout << endl<<endl;
agecheck: cout <<"Enter employee age
: ";
cin >> eage;
cout << endl;
if(eage>70 || eage<18){
cout<<"\nRe";
goto agecheck;
}esalary: cout <<"\nEnter employee salary : ";
cin >> esalary;
cout << endl;
employees[n++].get_data(ename, etitle,eage,esalary);
cout <<"\n\nContinue with the next employee? Type n or N to stop the data entry. ";
cin >> again;
cin.ignore();
cout <<endl;
} while(again =='y');
cout << "\n\n\t\t EMPLOYEE STATISTICAL REPORT" << endl;
cout <<endl;
cout <<"EMPLOYEE NAME" <<setw(20)<<"EMPLOYEE TITLE" <<setw(10)<< "AGE" for (int
i=0; i<n; i++)
{
employees[i].display_employee_list();
}
getch();
return 0;
}
Department of Computer Science, Christ University

C++ Lab

OUTPUT:

Department of Computer Science, Christ University

10

C++ Lab

Program Number
Program Name
Date implemented

11

: 3
: To implement Passing and returning parameters by
reference
: Novemeber 29, 2012

In this program, the details of an outlet are entered and the profit or loss for each
outlet is calculated by passing and returning parameters by reference.
/***************************************************************
* Author: Shophi Philip
***************************************************************/
#include<iostream.h>
#include<iostream.h>
#include<conio.h>
class calculator
{
private:
float value,profit,loss,capital;
char valuech[10],capitalch[10];
public:
void read();
void display();
void calc(calculator &x,calculator &y);
friend calculator &higher(calculator &x,calculator &y);
};
/* Function to validate string values*/
int isstring(char s[])
{
int i=0;
while(s[i])
{
if(!((s[i]>=65 && s[i]<92) || (s[i]>=97 && s[i]<123) || s[i]==32))
{
return 0;
}
i++;
}
return 1;
}
/* Function to validate integer values*/
int isint(char s[])
{
int i=0;
while(s[i])
{
if(!((s[i]>=48 && s[i]<=57)))
{
return 0;
}
i++;
}
return 1;
}
Department of Computer Science, Christ University

C++ Lab

/* Function to validate float values*/


int isfloat(char s[])
{
int i=0,f=0;
while(s[i])
{
if(!((s[i]>=48 && s[i]<=57)))
{
if(f==0&&s[i]=='.')
{
f=1;
i++;
continue;
}
return 0;
}
i++;
}
return 1;
}
/* Function to enter values*/
void calculator::read()
{
value : cin>>valuech;
if(!isfloat(valuech))
{ printf("\nInvalid Amount : Try Again : ");
goto value;}
value=atof(valuech);
}
void calculator::display()
{
cout<<value;
}
/* Function to find higher value*/
calculator &higher(calculator &income,calculator &expense)
{
if(income.value>expense.value)
{
return income;
}
else
return expense;
}
/* Function to calculate profit or loss*/
void calculator::calc(calculator &income,calculator &expense)
{
cout<<"\n____________________________________________\n";
if(income.value>expense.value)
{
cout<<"\n\nIncurred profit of
: Rs.";
profit=income.value - expense.value;
cout<<profit;
cout<<"\n\n K E E P I T U P!!!\n";
cout<<"\n\nEnter capital for the next month : Rs.";
Department of Computer Science, Christ University

12

C++ Lab

13

capital : cin>>capitalch;
if(!isfloat(capitalch))
{ printf("\nInvalid Amount ( Try Again ): ");
goto capital;}
capital=atof(capitalch);
cout<<"\n\nTOTAL INVESTMENT FOR THE NEXT MONTH : Rs.";
cout<<profit+capital;
}
else
{
cout<<"\n\nIncurred loss of
: Rs.";
loss=expense.value - income.value;
cout<<loss;
cout<<"\n\nBEWARE FOR THE NEXT MONTH!!!";
cout<<"\n\nEnter capital for the next month : Rs.";
capitalloss : cin>>capitalch;
if(!isfloat(capitalch))
{ printf("\nInvalid Amount ( Try Again ): ");
goto capitalloss;}
capital=atof(capitalch);
cout<<"\n\nTOTAL INVESTMENT FOR THE NEXT MONTH : Rs.";
cout<<loss+capital;
}
}
int main()
{
calculator in,exp;
char month[20],company[20];
cout<<"\n@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*
@*@*@*@*@*@*@*@*@*@*@*@*@*@";
printf("\n\n
M A L L M A N A G E M E N T \n\n");
cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@
*@*@*@*@*@*@*@*@*@*@*@*@*@\n\n";
cout<<endl<<endl<<endl;
cout<<"******************* P R O F I T , L O S S D E T A I L S ******************\n\n";
company: cout<<"\nEnter company
: ";
fflush(stdin);
cin>>company;
if(!isstring(company))
{ cout<<"Invalid Month ( Try Again )\n";
goto company;}
month: cout<<"\nEnter month
: ";
fflush(stdin);
cin>>month;
if(!isstring(month))
{ cout<<"Invalid Month ( Try Again )\n";
goto month;}
cout<<"\nEnter income for "<<month<<" : Rs.";
in.read();
cout<<"\nEnter expense for "<<month<<" : Rs.";
exp.read();
calculator &z=higher(in,exp);
z.calc(in,exp);
getch();
return 0;
}

Department of Computer Science, Christ University

C++ Lab

OUTPUT:

Department of Computer Science, Christ University

14

C++ Lab

Department of Computer Science, Christ University

15

C++ Lab

Program Number
Program Name
Date implemented

16

: 4
: To demonstrate Function Overloading
: December 3, 2012

In this program, the billing of an outlet is demonstrated by function overloading.


/***************************************************************
* Author: Shophi Philip
***************************************************************/
#include<iostream.h>
#include<iostream.h>
#include<conio.h>
#include <iostream.h>
#include <conio.h>
class billing
{
private:
int disc1,disc2,disc3,disc4,billno,cash,billamount;
public:
void get()
{
cout<<"Enter the bill number : ";
cin>>billno;
cout<<endl;
}
/* Function to validate string values*/
int isstring(char s[])
{
int i=0;
while(s[i])
{
if(!((s[i]>=65 && s[i]<92) || (s[i]>=97 && s[i]<123) || s[i]==32))
{
return 0;
}
i++;
}
return 1;
}
/* Function to validate integer values*/
int isint(char s[])
{
int i=0;
while(s[i])
{
if(!((s[i]>=48 && s[i]<=57)))
{
return 0;
}
i++;
}
return 1;
}
Department of Computer Science, Christ University

C++ Lab

/* Function to validate float values*/


int isfloat(char s[])
{
int i=0,f=0;
while(s[i])
{
if(!((s[i]>=48 && s[i]<=57)))
{
if(f==0&&s[i]=='.')
{
f=1;
i++;
continue;
}
return 0;
}
i++;
}
return 1;
}
/* Function to enter one bill value*/
void sum(int cash)
{
billamount=cash;
}
/* Function adds two bill amounts*/
void sum(billing b4, billing b5)
{
b4.billamount=b4.billamount+b5.billamount;
cout<<"\n\nTOTAL BILL AMOUNT : "<<b4.billamount;
getch();
}
/* Function adds two product prices*/
float sum(float a,int b)
{
cout<<"Enter discount for product 1 : ";
cin>>disc1;
cout<<"Enter discount for product 2 : ";
cin>>disc2;
return((float)a+b-disc1-disc2);
}
/* Function adds three product prices*/
int sum(int a,int b,int c)
{
cout<<"Enter discount for product 1 : ";
cin>>disc1;
cout<<"Enter discount for product 2 : ";
cin>>disc2;
cout<<"Enter discount for product 3 : ";
cin>>disc3;
return(a+b+c-disc1-disc2-disc3);
}

Department of Computer Science, Christ University

17

C++ Lab

18

/* Function adds four product prices*/


int sum(int a,int b,int c,int d)
{
cout<<"Enter discount for product 1 : ";
cin>>disc1;
cout<<"Enter discount for product 2 : ";
cin>>disc2;
cout<<"Enter discount for product 3 : ";
cin>>disc3;
cout<<"Enter discount for product 4 : ";
cin>>disc4;
return(a+b+c+d-disc1-disc2-disc3-disc4);
}
/* Function adds n product prices */
int sum(int a[],int n)
{
int sum=0,disc[50];
for(int i=0;i<n;i++)
{
cout<<"Enter discount for Product "<<i<<" : ";
cin>>disc[i];
sum=sum+a[i]-disc[i];
}
return(sum);
}
};
int main()
{
cout<<"\n@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*
@*@*@*@*@*@*@*@*@*@*@*@*@*@";
printf("\n\n
M A L L M A N A G E M E N T \n\n");
cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@
*@*@*@*@*@*@*@*@*@*@*@*@*@\n\n";
billing b1,b2;
int prod1,prod2,prod3,prod4,result,bill1,bill2,bill3;
float prod1f,prod2f,prod3f,prod4f,resultf;
char cases;
cout<<endl<<endl<<endl;
cout<<"*********************** B I L L I N G D E T A I L S ************************";
cout<<"\n\n1. Two Products";
cout<<"\n\n2. Three Products";
cout<<"\n\n3. Four Products";
cout<<"\n\n4. Select your number of Products";
cout<<"\n\n5. Bill calculation";
cout<<"\n\nEnter Your Choice : ";
cin>>cases;
cout<<"\n\n---------------------------------\n";
switch(cases)
{
case '1':
cout<<"\n\n\t\t2 PRODUCTS\n";
cout<<"\nEnter price for 2 Products : \n";
cin>>prod1>>prod2;
resultf=b1.sum(prod1,prod2);
cout<<"\nTotal ="<<resultf;
break;

Department of Computer Science, Christ University

C++ Lab

case '2':
cout<<"\n\n\t\t3 PRODUCTS\n";
cout<<"\nEnter price for 3 Products : \n";
cin>>prod1>>prod2>>prod3;
result=b1.sum(prod1,prod2,prod3);
cout<<"\nTotal ="<<result;
break;

case '3':
cout<<"\n\n\t\t4 PRODUCTS\n";
cout<<"\nEnter 4 Products : \n";
cin>>prod1>>prod2>>prod3>>prod4;
result=b1.sum(prod1,prod2,prod3,prod4);
cout<<"\nTotal ="<<result;
break;
case '4':
cout<<"\n\nHow many Products You want to enter:-";
int no;
cin>>no;
int num[50];
cout<<"\nEnter price for "<<no<<" Products : \n";
for(int i=0;i<no;i++)
cin>>num[i];
result=b1.sum(num,no);
cout<<"\nTotal ="<<result;
case '5':
billing b3,b4,b5;
cout<<"\n1. ";
b4.get();
cout<<"2. ";
b5.get();
cout<<"\n\nEnter first bill amount : ";
cin>>bill2;
cout<<"\n\nEnter second bill amount : ";
cin>>bill3;
b4.sum(bill2);
b5.sum(bill3);
b3.sum(b4,b5);
break;
}
cout<<"\n---------------------------------\n";
getch();
return 0;
}

Department of Computer Science, Christ University

19

C++ Lab

OUTPUT:

Department of Computer Science, Christ University

20

C++ Lab

Program Number
Program Name
Date implemented

21

: 5
: To demonstrate pointer sort operation
: December 6, 2012

In this program, the details of the employees are entered and displayed in a sorted
manner using pointer sort operation.
/***************************************************************
* Author: Shophi Philip
***************************************************************/

#include <iostream.h>
#include "validations.h"
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<string.h>
using namespace std;
class employeedetails
{
private:
char name[15];
int sal,dedamt,allowamt;
int salary;
public:
/* Function to enter employee salary*/
void getdata()
{
cout<<"\n\nEnter name
: ";
cin>>name;
cout<<"\n\nEnter basic salary : ";
cin>>sal;
cout<<"\n\nEnter Deduction amount : " ;
cin>>dedamt;
cout<<"\n\nEnter Allowance amount : " ;
cin>>allowamt;
calculate(sal,dedamt,allowamt);
}
/* Function to calculate total salary*/
void calculate(int sal, int ded, int allow)
{
salary=sal+allowamt-dedamt;
}
/* Function displays bill details*/
void putdata()
{
cout<<name<<"\t "<<sal<<"\t "<<dedamt<<"\t
}

Department of Computer Science, Christ University

"<<allowamt<<"\t

"<<salary<<endl;

C++ Lab

22

/* Function returns point value*/


char *getname()
{
return name;
}
};

int main()
{
int n;
void sort(employeedetails **,int);
employeedetails *emp[10];
printf("\n\n
M A L L M A N A G E M E N T \n\n");
cout<<endl<<endl<<endl;
cout<<"*********************** E M P L O Y E E D E T A I L S ************************";
cout<<"\n\nEnter Total no. of employees to be saved : ";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"\n_________________________________________\n";
cout<<"Enter employee number "<<i+1<<" details : ";
cout<<"\n_________________________________________\n";
emp[i]=new employeedetails;
emp[i]->getdata();
}
cout<<"\nYOUR ENTRY : \n\n";
cout<<"\n--------------------------------------------------------\n";
cout<<"\nNAME \t BS \t DED AMT \tALLOW AMT \t SALARY\n";
cout<<"\n--------------------------------------------------------\n";
for(int i=0;i<n;i++)
{
emp[i]->putdata();
}
sort(emp,n);
cout<<"\nSORTED ENTRY LIST: \n";
cout<<"\n--------------------------------------------------------\n";
cout<<"\nNAME \t BS \t DED AMT \tALLOW AMT \t SALARY\n";
cout<<"\n--------------------------------------------------------\n";
for(int i=0;i<n;i++)
{
emp[i]->putdata();
}
getch();
return 0;
}
/* Function sorts employee names*/
void sort(employeedetails **s,int n)
{
void swap(employeedetails **s,employeedetails **);
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
swap(s+i,s+j);
}

Department of Computer Science, Christ University

C++ Lab

/* Function sorts swap names*/


void swap(employeedetails **s1,employeedetails **s2)
{
if(strcmp((*s1)->getname(),(*s2)->getname())>0)
{
employeedetails *temp=*s1;
*s1=*s2;
*s2=temp;
}
}

Department of Computer Science, Christ University

23

C++ Lab

OUTPUT:

Department of Computer Science, Christ University

24

C++ Lab

Program Number
Program Name
Date implemented

25

: 6
: To overload operators incr & decr operators with post
& pre forms; [], ( ) and arithmetic operators
: December 13, 2012

In this program, the bills of the different outlets in a mall are considered and the total
amount is calculated using operator overloading.
/***************************************************************
* Author: Shophi Philip
***************************************************************/
#include<iostream.h>
#include<iostream.h>
#include<conio.h>
#include <iostream.h>
#include "validations.h"
class BillDetails
{
private:
int BId,SNum,Amt;
char BillName[5],BillId[5],ShopNo[5],Amount[5];
public:
int i;
void get();
void operator()();
void operator[](BillDetails );
void operator++();
void operator--();
void operator+(BillDetails );
};
/* Function to enter bill details*/
void BillDetails :: get()
{
LL2:
cout<<"\nEnter The Bill Id\n"<<endl;
cin>>BillId;
if(!isint(BillId)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL2;}
BId=atoi(BillId);
LL3:
cout<<"\nEnter The Shop Name\n"<<endl;
cin>>BillName;
if(!isstring(BillName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL3;}
LL1:
cout<<"\nEnter The Shop Id\n"<<endl;
cin>>ShopNo;
if(!isint(ShopNo)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL1;}
SNum=atoi(ShopNo);
LL4:
cout<<"\nEnter The Bill Amount\n"<<endl;
cin>>Amount;
if(!isint(Amount)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL4;}
Amt=atoi(Amount);
}

Department of Computer Science, Christ University

C++ Lab

/* Function displays bill details by overloading () operator*/


void BillDetails :: operator()()
{
cout<<"\n\t";
cout<<BillName;
cout<<"\t\t"<<ShopNo;
cout<<"\t\t\t"<<Amount;
}
/* Function displays bill details by overloading [] operator*/
void BillDetails::operator[](BillDetails x)
{
cout<<"\n\n\n\n-------------------------------------------------------------------------------\n";
cout<<"\t\tBILL DETAILS\n\t";
cout<<"\n-------------------------------------------------------------------------------\n\n\n";
cout<<"Bill With Higher Amount "<<"\n\n";
cout<<"\n\n\t----------------------------------------------------"<<endl;
cout<<"\n\tBillName\tShopNumber\t\tAmount\n";
cout<<"\t----------------------------------------------------"<<endl;
if(x.Amt>Amt)
{
cout<<"\n\t";
cout<<x.BillName;
cout<<"\t\t"<<x.ShopNo;
cout<<"\t\t\t"<<x.Amount;
}
else if(Amt>x.Amt)
{
cout<<"\n\t";
cout<<BillName;
cout<<"\t\t"<<ShopNo;
cout<<"\t\t\t"<<Amount;
}
else
{
cout<<"\n\n\n\tSame Amount\n\n";
}
}
/* Function displays bill details by overloading ++ operator*/
void BillDetails::operator ++()
{
int incre;
cout<<"\n\nEnter the amount to be added : ";
cin>>incre;
Amt=Amt+incre;
cout<<"\n\n\n\n-------------------------------------------------------------------------------\n";
cout<<"\t\tBILL DETAILS\n\t";
cout<<"\n-------------------------------------------------------------------------------\n\n\n";
cout<<"\n\n\t----------------------------------------------------"<<endl;
cout<<"\n\tBillName\tShopNumber\t\tAmount+Increment\n";
cout<<"\t----------------------------------------------------------"<<endl;
cout<<"\n\t";
cout<<BillName;
cout<<"\t\t"<<ShopNo;
cout<<"\t\t\t"<<Amt;
}

Department of Computer Science, Christ University

26

C++ Lab

27

/* Function displays bill details by overloading -- operator*/


void BillDetails::operator --()
{
int decre;
cout<<"\n\nEnter the amount to be reduced : ";
cin>>decre;
Amt=Amt-decre;
cout<<"\n\n\n\n-------------------------------------------------------------------------------\n";
cout<<"\t\tBILL DETAILS\n\t";
cout<<"\n-------------------------------------------------------------------------------\n\n\n";
cout<<"\n\n\t----------------------------------------------------"<<endl;
cout<<"\n\tBillName\tShopNumber\t\tAmount+Decrement\n";
cout<<"\t----------------------------------------------------------"<<endl;
cout<<"\n\t";
cout<<BillName;
cout<<"\t\t"<<ShopNo;
cout<<"\t\t\t"<<Amt;
}
/* Function displays bill details by overloading + operator*/
void BillDetails::operator +(BillDetails x)
{
int NewAmt;
NewAmt=x.Amt+Amt;
cout<<"\n\n\n\n-------------------------------------------------------------------------------\n";
cout<<"\t\tBILL DETAILS\n\t";
cout<<"\n-------------------------------------------------------------------------------\n\n\n";
cout<<"Full Amount Settlement : "<<NewAmt<<"\n\n";
}
int main()
{
cout<<"\n\n\t";
cout<<"\n@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*
@*@*@*@*@*@*@*@*@*@*@*@*@*@";
printf("\n\n
M A L L M A N A G E M E N T \n\n");
cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@
*@*@*@*@*@*@*@*@*@*@*@*@*@\n\n";
int ch;
char choise[5];
BillDetails c1,c2;
c1.get();
c2.get();
do
{
cout<<"\n\n1. Add\n\n";
cout<<"\n\n2. Compare\n\n";
cout<<"\n\n3. Increment the first bill\n\n";
cout<<"\n\n4. Increment the second bill\n\n";
cout<<"\n\n5. Decrement the first bill\n\n";
cout<<"\n\n6. Decrement the second bill\n\n";
cout<<"\n\n7. Display\n\n";
Label:
cout<<"\n\nEnter Your Choise\n\n";
cin>>choise;
if(!isint(choise)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto Label;}
ch=atoi(choise);
switch(ch)
{
Department of Computer Science, Christ University

C++ Lab

case 1:
c1+c2;
break;
case 2:
c1[c2];
break;
case 3:
++c1;
break;
case 4:
++c2;
break;
case 5:
--c1;
break;
case 6:--c2;
break;
case 7: cout<<"\n\n\n\n-------------------------------------------------------------------------------\n";
cout<<"\t\tBILL DETAILS\n\t";
cout<<"\n-------------------------------------------------------------------------------\n\n\n";
cout<<"\n\n\t----------------------------------------------------"<<endl;
cout<<"\n\tBillName\tShopNumber\t\tAmount\n";
cout<<"\t----------------------------------------------------"<<endl;
c1();
c2();
break;
default:
break;
}
getch();
}while(ch>0&&ch<5);
getch();
return(0);
}

Department of Computer Science, Christ University

28

C++ Lab

OUTPUT:

Department of Computer Science, Christ University

29

C++ Lab

Program Number
Program Name
Date implemented

30

: 7
: To demonstrate Friend functions and Friend class
: December 10, 2012

In this program, the details of the employee are entered and the salary is calculated
and displayed by using friend functions.
/***************************************************************
* Author: Shophi Philip
***************************************************************/
#include<iostream.h>
#include<conio.h>
class extra;
class details
{
char name[20],b_name[20],id[5],outlet[20];
float bs,bonus;
float total,net_sal;
char bsch[20],bonusch[20],totalch[20],net_salch[20];
public:
void getdata(void);
void display(void);
friend details calc(details,extra);
friend void displaydetails(details,extra);
};
class extra
{
char d_name[20],a_name[20],l_name[20],;
float leave_p,allow_p,deduc_p;
float deductionamtval;
float allowamt;
char allowamtch[20];
char deduc_pch[20],allow_pch[20],leave_pch[20];
char deductionamtch[20];
float total_d,total_l,total_a;
char total_dch[20],total_lch[20],total_ach[20];
float deduc,allow,leave;
char deducch[20],allowch[20],leavech[20];
float x,y,z;
char xch[20],ych[20],zch[20];
int leave_no,allow_no,deduc_no,ot;
char leave_noch[20],allow_noch[20],deduc_noch[20],otch[20];
public:
friend class details;
void getdata(void);
void display(void);
friend details calc(details,extra);
friend void displaydetails(details,extra);
};
/* Function used to validate string values*/
int isstring(char s[])
{
int i=0;
Department of Computer Science, Christ University

C++ Lab

while(s[i])
{
if(!((s[i]>=65 && s[i]<92) || (s[i]>=97 && s[i]<123) || s[i]==32))
{
return 0;
}
i++;
}
return 1;
}
/* Function used to validate integer values*/
int isint(char s[])
{
int i=0;
while(s[i])
{
if(!((s[i]>=48 && s[i]<=57)))
{
return 0;
}
i++;
}
return 1;
}
/* Function used to validate float values*/
int isfloat(char s[])
{
int i=0,f=0;
while(s[i])
{
if(!((s[i]>=48 && s[i]<=57)))
{
if(f==0&&s[i]=='.')
{
f=1;
i++;
continue;
}
return 0;
}
i++;
}
return 1;
}
/* Function to enter details about the employee*/
void details::getdata(void)
{
name: cout<<"Enter name of the employee
: ";
fflush(stdin);
cin>>name;
if(!isstring(name))
{ cout<<"Invalid Name : Try Again\n";
goto name;}
cout<<"Enter id
: ";
cin>>id;
outlet: cout<<"Enter Outlet name
: ";
Department of Computer Science, Christ University

31

C++ Lab

fflush(stdin);
cin>>outlet;
if(!isstring(outlet))
{ cout<<"Invalid Name : Try Again\n";
goto outlet;}
bs: cout<<"Enter the Basic Salary of the Employee : ";
cin>>bsch;
if(!isfloat(bsch))
{ printf("Invalid Amount : Try Again\n");
goto bs;}
bs=atof(bsch);
}
/* Function displays details of the shop*/
void details::display(void)
{
cout<<"\nName : "<<name;
cout<<"\nId : "<<id;
cout<<"\nOutlet : "<<outlet;
}
/* Function to enter data about the employee salary*/
void extra::getdata(void)
{
do
{
cout<<"Enter the number of Allowances : ";
cin>>allow_noch;
if(isint(allow_noch)==0)
printf("\n WARNING: ERROR IN INPUT, TRY AGAIN !!!");
}while(isint(allow_noch)==0);
allow_no=atoi(allow_noch);
for(int i=0;i<allow_no;i++)
{
allow: cout<<"Enter the Allowance Name
: ";
fflush(stdin);
cin>>a_name;
if(!isstring(a_name))
{ cout<<"Invalid Name : Try Again\n";
goto allow;}
allowamt: cout<<"Enter the Allowance Amount
: ";
cin>>allow_p;
total_a=total_a+allow_p;
}
do
{
cout<<"Enter the number of Deductions
: ";
cin>>deduc_noch;
}while(isint(deduc_noch)==0);
deduc_no=atoi(deduc_noch);
for(int j=0;j<deduc_no;j++)
{
deduc: cout<<"Enter the Deduction Name
: ";
fflush(stdin);
cin>>d_name;
if(!isstring(d_name))
{ cout<<"Invalid Name : Try Again\n";
goto deduc;}
deducamt: cout<<"Enter the Deduction Amount
: ";
Department of Computer Science, Christ University

32

C++ Lab

33

cin>>deductionamtval;
total_d=total_d+deductionamtval;
}
do
{
cout<<"Number of overtime hours : ";
cin>>otch;
if(isint(otch)==0)
printf("\n WARNING: ERROR IN INPUT, TRY AGAIN !!!");
}while(isint(otch)==0);
ot=atoi(otch);
}
/* Function displays salary details*/
void displaydetails(details d,extra e)
{
cout<<"ID:"<<d.id;
cout<<"NAME:"<<d.name;
cout<<"BASIC SALARY:"<<d.bs;
cout<<"NET SALARY PAID:"<<d.net_sal;
}
/* Function displays allowance details*/
void extra::display(void)
{
cout<<"\nAllowance amount : "<<total_a;
cout<<"\nNumber of over time hours : "<<ot;
}
/* Function calculates total salary*/
details calc(details d,extra e)
{
details temp;
if(e.ot>2)
d.bs=d.bs+(e.ot*1000);
temp.total=e.total_a;
temp.net_sal=d.bs+e.total_a-e.deductionamtval;
cout<<endl<<endl<<endl;
cout<<"*********************** E M P L O Y E E D E T A I L S ************************";
cout<<"\nID:"<<d.id;
cout<<"\nNAME:"<<d.name;
cout<<"\nBASIC SALARY:"<<d.bs;
cout<<"\n"<<"NET SALARY PAID: "<<temp.net_sal;
return (temp);
}
int main()
{
details d;
d.getdata();
d.display();
extra e;
e.getdata();
e.display();
details calculated;
calculated=calc(d,e);
getch();
return 0;
}
Department of Computer Science, Christ University

C++ Lab

OUTPUT:

Department of Computer Science, Christ University

34

C++ Lab

Program Number
Program Name
Date implemented

35

: 8
: To demonstrate possible Type Conversions
: December 17, 2012

In this program, the details of the employee are entered and the salary is calculated
and displayed by using type conversions.
/***************************************************************
* Author: Shophi Philip
***************************************************************/

#include <iostream.h>
#include "validations.h"
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<string.h>
using namespace std;
class employee1
{
private:
int empno;
double salary;
float DA,HRA;
public:
employee1(int en,double sal,float da,float hra)
{
empno=en;
salary=sal;
if((salary*.1)>1000)
{
DA=da;
}
else
DA=0;
HRA=salary*hra;
}
/* Function displays employee details*/
void display()
{
cout<<"\n\nEmployee number:"<<empno;
cout<<"\n\nSalary:"<<salary;
cout<<"\n\nDA:"<<DA;
cout<<"\n\nHRA:"<<HRA;
}

/* Function returns employee id*/


int getempno()
{
return(empno);
}

Department of Computer Science, Christ University

C++ Lab

/* Function returns employee salary*/


double getsal()
{
return(salary);
}
/* Function returns employees dearest allowance*/
float getda()
{
return(DA);
}
/* Function returns HRA of employee*/
float gethra()
{
return(HRA);
}
/* Function returns total salary by overloading double*/
operator double()
{
return(salary+DA+HRA);
}
};
class employee2
{
private:
int empno;
double grosssalary;
public:
employee2()
{
empno=0;
grosssalary=0;
}
employee2(int eN,double gs)
{
empno=eN;
grosssalary=gs;
}
/* Function displays employee details*/
void display()
{
cout<<"\nEmployee no. : "<<empno;
cout<<"\nGross salary : "<<grosssalary;
}
employee2(employee1 emp1)
{
empno=emp1.getempno();
grosssalary=emp1.getsal()+emp1.getda()+emp1.gethra();
}

Department of Computer Science, Christ University

36

C++ Lab

employee2(float sal)
{
grosssalary=sal;
grosssalary=(grosssalary*200000);
}
};
int main()
{
employee1 e1(127,20000,2000,.25);
e1.display();
employee2 e2,e3;
cout<<"\n\n-----------------------------------------------------------------------------";
double grosssal=e1;
e2=e1;
cout<<"\n\nGross salary="<<grosssal;
cout<<"\n\n-----------------------------------------------------------------------------";
e3=.25;
e3.display();
cout<<"\n\n-----------------------------------------------------------------------------";
getch();
return 0;
}

Department of Computer Science, Christ University

37

C++ Lab

OUTPUT:

Department of Computer Science, Christ University

38

C++ Lab

Program Number
Program Name
Date implemented

39

: 9
: To demonstrate implement different types of inheritances
like Multiple, Multilevel and Hybrid
: December 20, 2012

In this program, the details of the mall, the outlets and the customers are entered and
bill amounts calculated using inheritance.
/***************************************************************
* Author: Shophi Philip
***************************************************************/

#include <iostream.h>
#include "validations.h"
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<string.h>
class mall
{
public:
int id;
char name[20];
int outletno;
float sqft;
/* Function to enter Details of the Mall*/
void getdetails()
{
cout<<"************************** M A L L D E T A I L S ***************************";
cout<<"\n\nEnter id
: ";
cin>>id;
cout<<"\n\nEnter name
: ";
cin>>name;
cout<<"\n\nEnter number of outlets : ";
cin>>outletno;
cout<<"\n\nEnter square feet
: ";
cin>>sqft;
}
/* Function displays mall details*/
void putdetails()
{
cout<<"\n\t\t------------------------------------------------------\n";
cout<<"\n\n\t\t\t\t
M A L L ";
cout<<"\n\t\t------------------------------------------------------\n";
cout<<"\n\n\t\t\t\tID
: "<<id;
cout<<"\n\n\t\t\t\tNAME
: "<<name;
cout<<"\n\n\t\t\t\tOUTLETS : "<<outletno;
cout<<"\n\n\t\t\t\tSQUARE FEET : "<<sqft;
}
};
class shop
{
public:
int idshop;
Department of Computer Science, Christ University

C++ Lab

char shopname[20];
float rent,years,value;
/* Function to enter shop details*/
void getdatabill()
{
cout<<"\n\n************************** S H O P D E T A I L S
***************************";
cout<<"\n\nEnter shop id : ";
cin>>idshop;
cout<<"\n\nEnter shop name : ";
cin>>shopname;
}
/* Function to enter shop details*/
void getdata()
{
cout<<"\n\n************************** S H O P D E T A I L S
***************************";
cout<<"\n\nEnter shop id : ";
cin>>idshop;
cout<<"\n\nEnter shop name : ";
cin>>shopname;
cout<<"\n\nEnter shop rent : ";
cin>>rent;
cout<<"\n\nEnter shop year : ";
cin>>years;
}
/* Function calculates advance of the shop*/
void calc()
{
value=years*rent*10;
}
/* Function displays Shop details*/
void putdata()
{
cout<<"\n\t\t------------------------------------------------------\n";
cout<<"\n\n\t\t\t\t
S H O P";
cout<<"\n\t\t------------------------------------------------------\n";
cout<<"\n\n\t\t\t\tID
: "<<idshop;
cout<<"\n\n\t\t\t\tNAME : "<<shopname;
cout<<"\n\n\t\t\t\tRENT : "<<rent;
cout<<"\n\n\t\t\t\tYEARS : "<<years;
cout<<"\n\n\t\t\t\tADVANCE : "<<value;
}
/* Function displays bill details*/
void putdatabill()
{
cout<<"\n\t\t------------------------------------------------------\n";
cout<<"\n\n\t\t\t\t
S H O P";
cout<<"\n\t\t------------------------------------------------------\n";
cout<<"\n\n\t\t\t\tID : "<<idshop;
cout<<"\n\n\t\t\t\tNAME : "<<shopname;
}
};

Department of Computer Science, Christ University

40

C++ Lab

class customer:public mall,public shop


{
int custid;
char custaddr[20];
char custname[20];
public:
/* Function to enter customer details*/
void getcustomer()
{
cout<<"\n\n*********************** C U S T O M E R D E T A I L S
************************";
cout<<"\n\nEnter id
: ";
cin>>custid;
cout<<"\n\nEnter name : ";
cin>>custname;
cout<<"\n\nEnter Address : ";
cin>>custaddr;
}
/* Function displays customer details*/
void putcustomer()
{
cout<<"\n\t\t------------------------------------------------------\n";
cout<<"\n\n\t\t\t\t
C U S T O M E R";
cout<<"\n\t\t------------------------------------------------------\n";
cout<<"\n\n\t\t\t\tID
: "<<custid;
cout<<"\n\n\t\t\t\tNAME : "<<custname;
cout<<"\n\n\t\t\t\tADDRESS : "<<custaddr;
}
};
class items:public customer
{
public:
int id[10],qty[10],items[20];
int price[20],t;
char name[20];
int n;
/* Function to enter item details*/
void getdata()
{
cout<<"\n\n*********************** I T E M D E T A I L S ************************";
cout<<"\n\nEnter no. of items : ";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"\n\nEnter code : ";
cin>>id[i];
cout<<"\n\nEnter name : ";
cin>>name;
cout<<"\n\nEnter price : ";
cin>>price[i];
cout<<"\n\nEnter quantity : ";
cin>>qty[i];
}
}
};
Department of Computer Science, Christ University

41

C++ Lab

42

class bill:public items


{
int tot;
public:
void billing()
{
tot=0;
for(int i=0;i<n;i++)
{
tot=tot+(qty[i]*price[i]);
}
}
/* Function displays product details*/
void display()
{
cout<<"\n------------------------------------------------------\n";
cout<<"\n\nID\t NAME\t QUANTITY\t PRICE";
for(int i=0;i<n;i++)
{
cout<<endl;
cout<<" "<<id[i];
cout<<"\t "<<name[i];
cout<<"\t "<<qty[i];
cout<<"\t
"<<price[i];
}
cout<<"\n------------------------------------------------------\n";
cout<<"\n\nTOTAL : "<<tot;
}
};
int main()
{
cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@
*@*@*@*@*@*@*@*@*@*@*@*@*@";
printf("\n\n
M A L L M A N A G E M E N T \n\n");
cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@
*@*@*@*@*@*@*@*@*@*@*@*@*@";
cout<<endl<<endl<<endl;
int ch;
char choice;
customer c1;
bill b1;
c1.getdetails();
c1.putdetails();
cout<<endl;
cout<<"\n\n*********************** C H O I C E D E T A I L S ************************";
cout<<endl;
cout<<"\n\n1.Shop details";
cout<<"\n\n2.Billing";
cout<<"\n\nEnter your choice : ";
cin>>ch;
switch(ch)
{
case 1: c1.getdata();
cout<<"\n\nDo you want to go to the billing module ";
cin>>choice;
if(choice=='y')
Department of Computer Science, Christ University

C++ Lab

{
c1.calc();
c1.putdata();
c1.getcustomer();
c1.putcustomer();
bill b1;
b1.getdata();
b1.billing();
b1.display();
}
else
{
c1.putdata();
}
break;
case 2: c1.getdatabill();
c1.calc();
c1.putdatabill();
c1.getcustomer();
c1.putcustomer();
b1.getdata();
b1.billing();
b1.display();
break;
}
cout<<"\n\n\t\t\t\tTHANK YOU";
getch();
return 0;
}

Department of Computer Science, Christ University

43

C++ Lab

OUTPUT:

Department of Computer Science, Christ University

44

C++ Lab

Department of Computer Science, Christ University

45

C++ Lab

Program Number
Program Name
Date implemented

46

: 10
: To demonstrate the use of Abstract class
: January 3, 2013

In this program, the details of the theatre section of a mall are enterd and bill amounts
calculated using Abstract classes.
/***************************************************************
* Author: Shophi Philip
***************************************************************/
#include<iostream.h>
#include<conio.h>
#include<string.h>
class theatre
{
protected:
char custname[30];
int orderid;
char cname[30];
char movie[30];
int tickets;
float price;
public:
virtual void putdata()=0;
};
class bill:public theatre{
protected:
float c;
float vat,total_price;
public:
void getinfo();
void putdata();
void total();
};
/* Function to enter customer details*/
void bill::getinfo()
{
cout<<"\nEnter customer name:";
input:
cin>>custname;
int length=strlen(custname);
for(int l=0;l<length;l++)
{
if(int(custname[l])>=48 && int (custname[l])<=57)
{
cout<<"\t\tWrong Input Please Enter The character"<<endl;
goto input;
}
}
cout<<"\nEnter orderid
:";
cin>>orderid;
cout<<"\nEnter class name :";
input1:
cin>>cname;
Department of Computer Science, Christ University

C++ Lab

int length1=strlen(cname);
for(int p=0;p<length1;p++)
{
if(int(cname[p])>=48 && int (cname[p])<=57)
{
cout<<"\t\tWrong Input Please Enter The character"<<endl;
goto input1;
}
}
cout<<"\nEnter movie name :";
input2:
cin>>movie;
int length2=strlen(movie);
for(int q=0;q<length2;q++)
{
if(int(movie[q])>=48 && int (movie[q])<=57)
{
cout<<"\t\tWrong Input Please Enter The character"<<endl;
goto input2;
}
}
cout<<"\nEnter the number of tickets:";
cin>>tickets;
cout<<"\nEnter the price of each ticket:";
cin>>price;
}
/* Function displays customer details*/
void bill::putdata(){
cout<<"Name of the bookee
:"<<custname<<endl;
cout<<"Order id
:"<<orderid<<endl;
cout<<"Class name
:"<<cname<<endl;
cout<<"Movie
:"<<movie<<endl;
cout<<"Number of tickets
:"<<tickets<<endl;
cout<<"Price to be paid
:"<<price<<endl;
}
/* Function displays total bill amount*/
void bill::total(){
c=(tickets*price);
vat=(c*0.4);
total_price=c+vat;
cout<<"-----------------------------------------------"<<endl;
cout<<"VAT
:"<<vat<<endl;
cout<<"-----------------------------------------------"<<endl;
cout<<"Total amount
:"<<total_price<<endl;
cout<<"-----------------------------------------------"<<endl;
}
int main()
{
bill b;
b.getinfo();
b.putdata();
b.total();
getch();
return 0;
}

Department of Computer Science, Christ University

47

C++ Lab

OUTPUT:

Department of Computer Science, Christ University

48

C++ Lab

Program Number
Program Name
Date implemented

49

: 11
: To demonstrate the use of Virtual Functions
: January 3, 2013

In this program,the details of a restaurant and theatres in a mall are entered and its
monthly expense is calculated using virtual functions.
/***************************************************************
* Author: Shophi Philip
***************************************************************/

#include <iostream.h>
#include "validations.h"
#include<iostream.h>
#include<conio.h>
class shop
{
protected:
public:
float elec,water;
char name[10];
int sid;
float lastincome,thisincome,give,givenew;
/* Function to enter shop details*/
virtual void get()
{
cout<<"\n\nEnter name of the shop : ";
cin>>name;
cout<<"\n\nEnter id
: ";
cin>>sid;
}
/* Function displays shop details*/
virtual void put()
{
cout<<"\n------------------------------------------------------\n";
cout<<"\n\nShop id
: "<<sid;
cout<<"\n\nName
: "<<name;
cout<<"\n------------------------------------------------------\n";
}
/* Virtual Function*/
virtual void display()
{
}
};
class restaurant:virtual public shop{
public:
void get(){
cout<<"\n\nEnter last income
: ";
cin>>lastincome;
cout<<"\n\nEnter this month income : ";
cin>>thisincome;
}

Department of Computer Science, Christ University

C++ Lab

/* Function displays income details*/


void put(){
cout<<"\n------------------------------------------------------\n";
cout<<"\n\nLast month income : "<<lastincome;
cout<<"\n\nThis month income : "<<thisincome;
cout<<"\n------------------------------------------------------\n";
}
/* Function to enter monthly details*/
void display()
{
if(lastincome>thisincome)
{
cout<<"\n------------------------------------------------------\n";
cout<<"\n\nLoss for the month";
give=thisincome*.10;
cout<<"\n\nAmount to be paid without extra charges : "<<give;
cout<<"\n\nEnter electricity charge
: ";
cin>>elec;
cout<<"\n\nEnter water charge
: ";
cin>>water;
givenew=give+elec+water;
cout<<"\n------------------------------------------------------\n";
}
else
{
cout<<"\n\nProfit for the month";
give=thisincome*.30;
cout<<"\n\nAmount to be paid without extra charges : "<<give;
cout<<"\n\nEnter electricity charge
: ";
cin>>elec;
cout<<"\n\nEnter water charge
: ";
cin>>water;
givenew=give+elec+water;
}
cout<<"\n------------------------------------------------------\n";
cout<<"\n\nTotal Amount to be paid
: "<<givenew;
cout<<"\n------------------------------------------------------\n";
}
};
class theatre:virtual public shop
{
public:
void get(){
cout<<"\n------------------------------------------------------\n";
cout<<"\n\nEnter last income
: ";
cin>>lastincome;
cout<<"\n\nEnter this month income : ";
cin>>thisincome;
}
/* Function displays income details*/
void put()
{
cout<<"\n------------------------------------------------------\n";
cout<<"\n\nLast month income : "<<lastincome;
cout<<"\n\nThis month income : "<<thisincome;
}
Department of Computer Science, Christ University

50

C++ Lab

51

/* Function to enter monthly details*/


void display()
{
if(lastincome>thisincome)
{
cout<<"\n------------------------------------------------------\n";
cout<<"\n\nLoss for the month";
give=thisincome*.30;
cout<<"\n\nAmount to be paid without extra charges : "<<give;
cout<<"\n\nEnter electricity charge
: ";
cin>>elec;
cout<<"\n\nEnter water charge
: ";
cin>>water;
givenew=give+elec+water;
cout<<"\n------------------------------------------------------\n";
}
else
{
cout<<"\n------------------------------------------------------\n";
cout<<"\n\nProfit for the month";
give=thisincome*.40;
cout<<"\n\nAmount to be paid without extra charges : "<<give;
cout<<"\n\nEnter electricity charge
: ";
cin>>elec;
cout<<"\n\nEnter water charge
: ";
cin>>water;
givenew=give+elec+water;
cout<<"\n------------------------------------------------------\n";
}
cout<<"\n\nTotal Amount to be paid
: "<<givenew;
cout<<"\n------------------------------------------------------\n";
}
};
int main()
{
int ch;
cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@
*@*@*@*@*@*@*@*@*@*@*@*@*@";
printf("\n\n
M A L L M A N A G E M E N T \n\n");
cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@
*@*@*@*@*@*@*@*@*@*@*@*@*@";
cout<<endl<<endl<<endl;
shop *s;
shop ob1;
restaurant ob2;
theatre ob3;
s=&ob1;
s->get();
s->put();
s->display();
cout<<"\n\n*********************** C H O I C E D E T A I L S ************************";
cout<<endl;
cout<<"\n\n1.Restaurant";
cout<<"\n\n2.Theatre";
cout<<"\n\nEnter your choice : ";
cin>>ch;

Department of Computer Science, Christ University

C++ Lab

switch(ch)
{
case 1:
s=&ob2;
s->get();
s->put();
s->display();
break;
case 2:
s=&ob3;
s->get();
s->put();
s->display();
break;
}
getch();
return 0;
}

Department of Computer Science, Christ University

52

C++ Lab

OUTPUT:

Department of Computer Science, Christ University

53

C++ Lab

Program Number
Program Name
Date implemented

54

: 12
: To demonstrate function Templates, and overload the
function Templates
: January 28, 2013

In this program, the bills are calculated by providing discounts to the various classes
of customers using templates.
/***************************************************************
* Author: Shophi Philip
***************************************************************/
#include<iomanip.h>
#include<iostream>
#include<stdlib.h>
#include <conio.h>
#include<iostream>
#include<conio.h>
using namespace std;
template<class t1,class t2>
/* Function to calculate total bill amount with two generic variables */
float offerprice(t1 x,t2 y)
{
t1 total;
total=x-(y*x/100);
return total;
}
template<class t>
/* Function returns bill amount using one generic variable */
float offerprice(t x)
{
return x;
}
template <class T1, class T2>
class temp
{
T1 a;
T2 b;
public:
temp(T1 x, T2 y)
{
a = x;
b = y;
}
void show();
/* Function to calculate total bill amount*/
void cal()
{
double sum,tax,tot;
tot = a*b;
cout<<"\n-------------------------------";
Department of Computer Science, Christ University

C++ Lab

55

cout<<"\n\nAMOUNT WITHOUT TAX Rs. "<<tot;


}
/* Function to calculate total bill amount with tax */
void cal(float tax)
{
double sum,tot;
tot = a*b;
sum = tot + (tot * tax / 100);
cout<<"\n-------------------------------";
cout<<"\n\nAMOUNT WITH TAX Rs. "<<sum;
cout<<"\n-------------------------------";
}
};
/* Function displays product details */
template <class T1, class T2> void temp<T1, T2> :: show()
{
cout<<"\n\nPRODUCT ID : "<<a;
cout<<"\n\nPRODUCT TYPE : "<<b;
}
int main()
{
double price;
char ch;
int choice;
double discount;
cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@
*@*@*@*@*@*@*@*@*@*@*@*@*@";
printf("\n\n
M A L L M A N A G E M E N T \n\n");
cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@
*@*@*@*@*@*@*@*@*@*@*@*@*@";
cout<<endl<<endl<<endl;
cout<<"\n\n*********************** C H O I C E D E T A I L S ************************";
cout<<endl;
cout<<"\n\n1. Discount\n\n2. No Discount\n\n";
cout<<"\n\nEnter your choice : ";
cin>>choice;
switch(choice)
{
case 1: cout<<"\nEnter Commodity Price:Rs.";
cin>>price;
cout<<"\n\nRegular Customer?(Y/N): ";
cin>>ch;
switch(ch)
{
case 'Y': cout<<"\nEnter Discount(%):";
cin>>discount;
price=offerprice(price,discount);
cout<<"\n-------------------------------";
cout<<"\nTotal:"<<price;
cout<<"\n-------------------------------";
break;
case 'y':cout<<"\nEnter Discount(%): ";
cin>>discount;
price=offerprice(price,discount);
cout<<"\n-------------------------------";
cout<<"\nTotal:"<<price;
Department of Computer Science, Christ University

C++ Lab

cout<<"\n-------------------------------";
break;
case 'N':price=offerprice(price);
cout<<"\n-------------------------------";
cout<<"\nCharges:"<<price;
cout<<"\n-------------------------------";
break;
case 'n':price=offerprice(price);
cout<<"\n-------------------------------";
cout<<"\nCharges:"<<price;
cout<<"\n-------------------------------";
break;
}
cout<<"\n\n";
cout<<"\nEnter quantity :";
int n;
cin>>n;
price=offerprice(price,n);
cout<<"\n-------------------------------\n";
cout<<"\nPrice after discount:Rs"<<price;
cout<<"\n\n";
cout<<"\n-------------------------------\n";
break;
case 2: int id;
char name[10];
float qty;
double price1;
char ch1;
cout<<"\nEnter the product Id : ";
cin>>id;
cout<<"\nEnter the Product Type : ";
cin>>name;
temp <int ,char*> t(id,name);
cout<<"\nQuantity : ";
cin>>qty;
cout<<"\nPrice : ";
cin>>price1;
temp<float ,double> v(qty,price1);
cout<<"\n\n\nBILL\n\n ";
t.show();
v.cal();
v.cal(5.0);
break;
}
getch();
return 0;
}

Department of Computer Science, Christ University

56

C++ Lab

OUTPUT:

Department of Computer Science, Christ University

57

C++ Lab

Program Number
Program Name
Date implemented

58

: 13
: To demonstrate generic stack class and member functions
to perform stack operations
: February 4, 2013

In this program, we enter the details of the employee and calculate his salary and
display it systematically.
/***************************************************************
* Author: Shophi Philip
***************************************************************/
#include<iomanip.h>
#include<iostream>
#include<stdlib.h>
#include <conio.h>
#include<iostream>
#include<conio.h>
using namespace std;
template<class ams>
class stock
{
ams a[20];
int top;
public:
stock()
{
top=-1;
}
/* Function to push product details to stack*/
void push(ams g)
{
if((top+1)>= max)
{
cout<<"\n\nOVERFLOW OF STORAGE";
}
else
{
top++;
a[top]=g;
}
}
/* Function to pop product details from stack*/
ams pop()
{
ams product;
if(top==-1)
{\
return(-1);
}
else
{
product=a[top];
top--;
cout<<endl;
Department of Computer Science, Christ University

C++ Lab

cout<<product;
cout<<endl;
return product;
}
};
int main()
{
stock <int> i;
stock<int> q;
stock <float> p;
int id,ch,quan;
float price;
do{
cout<<endl<<endl<<endl;
cout<<"\n\t\t\t\t--------------------\n";
cout<<"\n\t\t\t\t THE STORE ";
cout<<"\n\t\t\t\t--------------------\n";
cout<<"\n\n\t\t\t\t 1.PUSH\n\n\t\t\t\t 2.POP\n\n\t\t\t\t 3.exit\n\n";
cout<<"\nEnter your choice : ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\nEnter Product Id
: ";
cin>>id;
cout<<"\nEnter the product Quantity : ";
cin>>quan;
cout<<"\nEnter the product Price : ";
cin>>price;
i.push(id);
q.push(quan);
p.push(price);
getch();
break;
case 2:
cout<<endl;
cout<<" The Product id , quantity and price are removed \n";
int h=i.pop( );
int j=q.pop( );
float k =p.pop( );
if(h!=-1)
{
cout<<"\n\t\t Details of removed product \n\t\t_________________\n";
cout<<"\n ID
: "<<h<<"\n QUANTITY : "<<j<<"\n PRICE : "<<k;
}
else
{
cout<<"\nOUT OF STOCK";
}
getch();
break;
}
}while(ch!=3);
getch();
return(0);
}

Department of Computer Science, Christ University

59

C++ Lab

OUTPUT:

Department of Computer Science, Christ University

60

C++ Lab

Program Number
Program Name
Date implemented

61

: 14
: To demonstrate I/O streams and functions
: February 11, 2013

In this program, the details of the employee are entered and and displayed by using
I/O streams and functions.
/***************************************************************
* Author: Shophi Philip
***************************************************************/
#include<iomanip.h>
#include<iostream>
#include<stdlib.h>
#include <conio.h>
using namespace std;
class employee
{
int id;
char name[10];
float sal,bonus,sal1;
public:
/* Function to enter employee details*/
void getdata()
{
cout.width(25);
cout<<"ENTER EMPLOYEE DETAILS "<<endl;
cout.setf(ios::left,ios::adjustfield);
cout.fill('*');
cout.width(35);
cout<<"\n";
cout<<"\n\n Enter employee id : ";
cin>>id;
cout<<"\n Enter employee name : ";
cin>>name;
cout<<"\n Enter the employee salary :";
cin>>sal;
cout<<"\n Enter the bonus :";
cin>>bonus;
sal1=sal+bonus;
}
/* Function displays employee details*/
void putdata()
{
cout.width(25);
cout<<"\n EMPLOYEE DETAILS ARE : "<<endl;
cout.setf(ios::left,ios::adjustfield);
cout.fill('_');
cout.width(30);
cout<<"\n";
cout<<"\nEmployee id " ;
cout << setfill ('x') << setw (10);
cout << id << endl;
cout.setf ( ios::oct, ios::basefield );
cout<<"\nEmployee id " << id << endl;
Department of Computer Science, Christ University

C++ Lab

cout.setf ( ios::hex, ios::basefield );


cout<< "Employee id " << id << endl;
cout.setf ( ios::dec, ios::basefield );
cout<<"Employee id "<< id << endl;
cout<<"NAME IS
: " << name<<endl;
cout<<"Total salary
: "<< sal1 << endl;
}
};
int main()
{
employee e;
e.getdata();
e.putdata();
getch();
}

Department of Computer Science, Christ University

62

C++ Lab

OUTPUT:

Department of Computer Science, Christ University

63

C++ Lab

Program Number
Program Name
Date implemented

64

: 15
: To overload << and >> operators as a member and as a
non-member operator functions
: February 18, 2013

In this program, the bill amounts are stored and calculated along with discounts by
using insertion and extraction operator overloading.
/***************************************************************
* Author: Shophi Philip
***************************************************************/
#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<ctype.h>
#include "validations.h"
using namespace std;
class product
{
public:
float amount,discount;
product operator+(product y);
friend ostream & operator<<(ostream &out,product x);
friend istream & operator>>(istream &in,product &x);
};
/* Function to add bill amount and discount*/
product product::operator+(product y)
{
product t;
t.amount=amount+y.amount;
t.discount=discount+y.discount;
return t;
}
/* Function to enter amount and discount details by overloading >> operator*/
istream & operator>>(istream &in,product &x)
{
in>>x.amount>>x.discount;
return in;
}
/* Function displays amount and discount details by overloading << operator*/
ostream & operator << (ostream &out,product x)
{
out<<" \n\nProduct Amount : "<<x.amount<<" Discount : "<<x.discount<<"\n";
return out;
}
int main()
{
int CId,ANum;
int Amount;
char productType[20],discount[10];
Department of Computer Science, Christ University

C++ Lab

65

char CustomerName[5],CustomerId[5],phone[5];
cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@
*@*@*@*@*@*@*@*@*@*@*@*@*@";
printf("\n\n
M A L L M A N A G E M E N T \n\n");
cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@
*@*@*@*@*@*@*@*@*@*@*@*@*@";
cout<<"\t\t\t\t***************\t"<<endl;
cout<<"\t\t\t\tBILL\n\t"<<endl;
cout<<"\t\t\t***************\n\n\t"<<endl;
LL2:
cout<<"\nEnter The Customer Id : "<<endl;
cin>>CustomerId;
if(!isint(CustomerId)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL2;}
CId=atoi(CustomerId);
LL3:
cout<<"\nEnter The Customer Name : "<<endl;
cin>>CustomerName;
if(!isstring(CustomerName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL3;}
LL1:
cout<<"\nEnter The Phone number : "<<endl;
cin>>phone;
if(!isint(phone)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL1;}
ANum=atoi(phone);
product prod1,prod2,prod3;
cout<<"\n\nEnter The First product Amount And its discount : \n";
cin>>prod1;
cout<<"\n\nEnter The Second product Amount And its discount : \n";
cin>>prod2;
prod3=prod1+prod2;
cout<<"";
cout<<prod1;
cout<<"";
cout<<prod2;
cout<<"\n\n\n TOTAL PAYMENT \n";
cout<<"********************\n";
cout<<prod3;
getch();
return(0);
}

Department of Computer Science, Christ University

C++ Lab

OUTPUT:

Department of Computer Science, Christ University

66

C++ Lab

Program Number
Program Name
Date implemented

67

: 16
: To create a file to store some records and search for a
particular record and display it
: February 25, 2013

In this program, the details of the cutomer and the bills are stored in a file and
retrieved by using various file operations.
/***************************************************************
* Author: Shophi Philip
***************************************************************/
#include<iostream>
#include <fstream>
#include<conio.h>
using namespace std;
class customer{
public:
int cid;
char cname[20];
int amount;
int discount;
/* Function to enter customer details*/
void getdata(){
cout<<"\n\nEnter the Customer id :";
cin>>cid;
cout<<"\n\nEnter the Customer name :";
cin>>cname;
cout<<"\n\nEnter the Bill Amount:";
cin>>amount;
cout<<"\n\nEnter the Discount:";
cin>>discount;
}
/* Function displays customer details*/
void putdata(){
cout<<"\nCustomer Id
:"<<cid;
cout<<"\nCustomer Name
:"<<cname;
cout<<"\nBill Amount
:"<<amount;
cout<<"\nDiscount
:"<<discount;
}
};
int main()
{
cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@
*@*@*@*@*@*@*@*@*@*@*@*@*@";
printf("\n\n
M A L L M A N A G E M E N T \n\n");
cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@
*@*@*@*@*@*@*@*@*@*@*@*@*@";
ofstream outfile;
outfile.open("customer.dat", ios::app);
cout << "\n\nWriting to the file..." << endl;
customer c;
c.getdata();
Department of Computer Science, Christ University

C++ Lab

outfile<<c.cid<<"\t"<<c.cname<<"\t"<<c.amount<<"\t"<<c.discount<<"\n";
outfile.close();
ifstream infile;
infile.open("customer.dat");
cout << "\n\nReading from the file...\n\n\n" << endl;
cout<<"____________________________________\n";
cout<<"CustID\tName\tAmount\tDiscount"<<endl;
cout<<"____________________________________\n";
char str[100];
while(infile){
infile.getline(str,100);
cout <<str<< endl;
}
infile.close();
getch();
return 0;
}

Department of Computer Science, Christ University

68

C++ Lab

OUTPUT:

Department of Computer Science, Christ University

69

You might also like