Documente Academic
Documente Profesional
Documente Cultură
SYBBA(CA)
Index
SLIP PROGRAMS SIGNATURE
NO.
1 A. Functions to calculate and display the salary of worker.
B. Create class Person which contains data member as Passport_Id,
Person_name,Nationality, Gender, Date_of_Birth, Date_of_Issue,
Date_of_expiry
3 A. Create and initialize the object by using parameterized
constructor and display date in dd-mm-yyyy format.
B. Create a base class Student(Roll_No, Name) which derives two
classes
4 A. Create a class Part which contains data members as Part_Id,
Part_Name, Part_Price
B. Create a base class Account Derive a two classes as
Saving_Account and Current_Account from Account.
5 A. Create a class Item with data members Item_Code, Item_Name,
Item_Price. Write member functions to accept and display Item
information also display number of objects created for a class.
6 A. Create a class which contains two dimensional integer array of
size mXn.
B.Create a class Time which contains data members as: Hours,
Minutes and Seconds.
7 A. Create a class which contains single dimensional integer array of
given size
B. Create a Base class Train containing protected data members as
Train_no, Train_Name. Derive a class Route (Route_id, Source,
Destination) from Train class.
8 A. Create a class Employee which contains data members as
Emp_Id, Emp_Name, Basic_Salary, HRA, DA, Gross_Salary
B. Overloading operators >> and << to accept and display a Date
also write a member function to validate a date.
13
A. Calculate area of cone, sphere and circle by using function
overloading
B. Create a class Matrix
Q.1A) Write a C++ program to create a class Worker with data members as
Worker_Name, No_of_Hours_worked, Pay_Rate. Write necessary member
functions to calculate and display the salary of worker. (Use default
value for Pay_Rate)
Q.1B) Create class Person which contains data member as Passport_Id,
Person_name, Nationality, Gender, Date_of_Birth, Date_of_Issue,
Date_of_expiry .
Write a c++ program to perform following member functions:
i. Enter details of all persons
ii. Display passport details of one person
iii. Display passport details of all persons
(Use Function overloading and Array of object).
1A)
#include<iostream.h>
#include<conio.h>
#include<string.h>
class Worker
{
char wname[20];
int n;
float pr;
public:
void accept(char lw[20], int ln, float lpr = 10)
{
strcpy(wname, lw);
n = ln;
pr = lpr;
}
void calculate_display()
{
cout<<"\nSalary of worker ="<<n * pr;
}
};
int main()
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
{ clrscr();
char wname[20];
int n;
Worker wobj;
cout<<"\nEnter wname, hours =";
cin>>wname>>n;
wobj.accept(wname, n);
wobj.calculate_display();
getch();
return 0;
}
1B)
#include<iostream.h>
#include<conio.h>
class Person
{
int pid;
char pname[20];
public:
void accept();
void display(int pid);
void display();
};
void Person :: accept()
{
cout<<"\nEnter pid, pname ";
cin>>pid>>pname;
}
void Person :: display()
{
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
parr[i].display(id);
}
getch();
return 0;
}
Q.3A) Write a C++ program to create a class Date which contains three data
members as dd, mm, yyyy. Create and initialize the object by using
parameterized constructor and display date in dd-mon-yyyy format.
(Input: 19-12-2014 Output: 19-Dec-2014) Perform validation for
month.
Q.3B) Create a base class Student(Roll_No, Name) which derives two
classes Academic_Marks(Mark1, Mark2,
Mark3) and Extra_Activities_Marks(Marks). Class Result(Total_Marks,
Grade) inherits both Academic_Marks and
Extra_Activities_Marks classes. (Use Virtual Base Class)
Write a C++ menu driven program to perform the following functions:
break;
case 2:
cout<<"\n"
<<dd<<"-Feb-"<<yy;
break;
case 3:
cout<<"\n"
<<dd<<"-Mar-"<<yy;
break;
case 4:
cout<<"\n"
<<dd<<"-Apr-"<<yy;
break;
case 5:
cout<<"\n"
<<dd<<"-May-"<<yy;
break;
case 6:
cout<<"\n"
<<dd<<"-Jun-"<<yy;
break;
case 7:
cout<<"\n"
<<dd<<"-Jul-"<<yy;
break;
case 8:
cout<<"\n"
<<dd<<"-Aug-"<<yy;
break;
case 9:
cout<<"\n"
<<dd<<"-Sep-"<<yy;
break;
case 10:
cout<<"\n"
<<dd<<"-Oct-"<<yy;
break;
case 11:
cout<<"\n"
<<dd<<"-Nov-"<<yy;
break;
case 12:
cout<<"\n"
<<dd<<"-Dec-"<<yy;
break;
default:
cout<<"\nI
nvalid month";
}
}
};
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
void main()
{
clrscr();int m,dt,y;
cout<<"\n Enter date : ";
cin>>dt;
cout<<"\n Enter month : ";
cin>>m;
cout<<"\n Enter year : ";
cin>>y;
date d(dt,m,y);
d.display();
getch();
}
3B)
#include<iostream.h>
#include<conio.h>
#include<string.h>
class student
{
public:
int roll_no;
char name[20];
student()
{
}
student(int rn,char na[20])
{
roll_no=rn;
strcpy(name,na);
}
};
class academic_marks:virtual public student
{
public:
int mark1,mark2,mark3;
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
academic_marks()
{
}
academic_marks(int m1,int m2,int m3)
{
mark1=m1;
mark2=m2;
mark3=m3;
}
};
class extra_activities_marks:virtual public student
{
public:
int mark4;
extra_activities_marks()
{
}
extra_activities_marks(int m4)
{
mark4=m4;
}
};
class result:public academic_marks,public extra_activities_marks
{
int total_marks;
float perc;
public:
result()
{
}
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
Q.4A) Write a C++ program to create a class Part which contains data
members as Part_Id, Part_Name, Part_Price. Create and Initialize all
values of Part object by using parameterized constructor and copy
constructor. Display the values of Part object. (Part_price should
be right justified with a precision of two digits)
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
}
void putdata()
{
cout<<"\npartid="<<part_id;
cout<<"\npartname="<<part_name;
cout<<"\npartprice="<<setw(10)<<setprecision(2)<<part_price;
}
};
int main()
{
clrscr();
int n,pi;
char pn[10];
float pp;
part p1;
cout<<"\nenter partid=";
cin>>pi;
cout<<"\nenter partname=";
cin>>pn;
cout<<"\nenter partprice=";
cin>>pp;
cout<<"\nobject for parameterized constructor:";
p1=part(pi,pn,pp);
p1.putdata();
cout<<"\nobject for copy constructor:";
part p2(p1);
p2.putdata();
getch();
return 0;
}
4B)
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
#include<iostream.h>
#include<conio.h>
class Account
{
public:
char name[10];
long cno;
public:
void getdata()
{
cout<<"\n Account holder
name : ";
cin>>name;
cout<<"\n contact no : ";
cin>>cno;
}
void display()
{
cout<<"\n Name :"<<name;
cout<<"\n contact No
:"<<cno;
}
};
class saving_Account:public Account
{
int acc_no;
float bal,T_bal;
public:
void getdata()
{ Account::getdata();
cout<<"\n Account no : ";
cin>>acc_no;
cout<<"\n Enter balance:
";
cin>>bal;
}
void cal()
{
T_bal=bal+(bal*0.05);
}
void display()
{ Account::display();
cout<<"\nAccount no :
"<<acc_no;
cout<<"\nbalance
:"<<bal<<endl;
cout<<"\nTotal balance
:"<<T_bal<<endl;
}
};
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
void cal()
{
bal=bal+(bal*(1.5/100));
}
void display()
{ Account::display();
cout<<"\n Account no :
"<<acc_no;
cout<<"\n Total balance
:"<<bal<<endl;
}
};
void main()
{
int i,n,n1,ch;
clrscr();
current_Account c[10];saving_Account s[10];
do
{cout<<"\n 1.Enter Current Account datails \n 2.Enter
Saving Account Details \n 3.Display Current Account Holder \n 4.Display
Saving Account Holders \n 0.Exit";
cout<<"\n Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1 : cout<<"\n Enter
how many current Account holders ? ";
cin>>n;
for(i=0;i<
n;i++)
{
c[i].getdata();
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
c[i].getdata();
}
break;
case 2 : cout<<"\n Enter
how many saving Account holders ? ";
cin>>n1;
for(i=0;i<
n1;i++)
{
s[i].getdata();
s[i].cal();
}
break;
case 3 : cout<<"\n Details
of curent account holders : ";
for(i=0;i<
n;i++)
{
c[i].cal();
c[i].display();
}
break;
case 4 : cout<<"\n Details
of saving account holders : ";
for(i=0;i<
n1;i++)
{
s[i].display();
}
break;
case 0 : break;
}
}while(ch!=0);
getch();
}
Q.6A) Write a C++ program to create a class which contains two dimensional
integer array of size mXn. Write a member function to display sum of
all elements of entered matrix. (Use Dynamic Constructor for
allocating memory and Destructor to free memory of an object)
Q.6B) Create a class Time which contains data members as: Hours, Minutes
and Seconds. Write C++ program to perform following necessary member
functions:
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
i. To read time
ii. To display time in format like: hh:mm:ss
To add two different times (Use Objects as argument)
6A)
#include<conio.h>
#include<iostream.h>
main()
{
int r,c,sum=0;
clrscr();
cout<<"\n Enter dimension ";
cin>>r;
cin>>c;
int **a;
a=new int*[r];//[s];
for(int i=0;i<r;i++)
{ a[i]=new int[c];
}
for(i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cout<<"\n enter data : ";
cin>>a[i][j];
}
}
for(i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cout<<"\t"<<a[i][j];
}
cout<<endl;
}
for(i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
sum=sum+a[i][j];
}
}
cout<<"\n sum of all elements of matrix : "<<sum;
getch();
}
6B)
#include<iostream.h>
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
#include<conio.h>
class Time
{
int hr,min,sec;
public:
void settime(int x,int y,int z)
{ hr=x;
min=y;
sec=z;
}
void showtime()
{ cout<<"\n"<<hr<<":"<<min<<":"<<sec<<endl;
}
Time add(Time t)
{
Time t1;
t1.sec=sec+t.sec;
t1.min=t1.sec/60;
t1.sec=t1.sec%60;
t1.min=t1.min+min+t.min;
t1.hr=t1.min/60;
t1.min=t1.min%60;
t1.hr=t1.hr+hr+t.hr;
return t1;
}
};
void main()
{
int h,m,s;
cout<<"\n Enter hr:\t";
cin>>h;
cout<<"\n Enter min:\t";
cin>>m;
cout<<"\n Enter sec:\t";
cin>>s;
Time t1;
t1.settime(h,m,s);
t1.showtime();
Time t2;
cout<<"\n Enter hr:\t";
cin>>h;
cout<<"\n Enter min:\t";
cin>>m;
cout<<"\n Enter sec:\t";
cin>>s;
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
t2.settime(h,m,s);
t2.showtime();
Time t3;
cout<<"\t Addition of 2 times : ";
t3=t1.add(t2);
t3.showtime();
getch();
}
void evnodd()
{
int i;
cout<<"even nos are : \t";
for(i=0;i<size;i++)
{
if(ptr[i]%2==0)
{
cout<<ptr[
i];
cout<<"\t"
;
}
}
cout<<"\n Odd nos are : \t ";
for(i=0;i<size;i++)
{
if(ptr[i]%2!=0)
{
cout<<ptr[
i];
cout<<"\t"
;
}
}
}
~dynamic()
{delete ptr;
}
};
void main()
{
int n;
clrscr();
cout<<"enter size";
cin>>n;
dynamic d(n);
d.display();
d.evnodd();
getch();
}
7B)
#include<iostream.h>
#include<conio.h>
#include<string.h>
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
class Train
{
protected:
char tname[20];
public:
void accept_td()
{
cout<<"\nEnter train name ";
cin>>tname;
}
};
class Route : public Train
{
};
class Reservation: public Route
{
char tclass[20];
public:
void accept_resd()
{
accept_td();
cout<<"\nEnter train class :";
cin>>tclass;
}
void display_trainclass_wise(char temp_class[20])
{
if(strcmp(temp_class,tclass) == 0)
{
display_res();
}
}
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
void display_res()
{
cout<<"\nT class = " <<tclass;
}
};
int main()
{
clrscr();
Reservation rarr[1];
char ttclass[20];
for(int i = 0;i < 1;i++)
rarr[i].accept_resd();
cout<<"\n\nEnter specified class ....";
cin>>ttclass;
for(i = 0; i<1;i++)
rarr[i].display_trainclass_wise(ttclass);
getch();
return 0;
}
Q.8A) Write a C++ program to create a class Employee which contains data
members as Emp_Id, Emp_Name, Basic_Salary, HRA, DA, Gross_Salary.
Write member functions to accept Employee information. Calculate and
display Gross salary of an employee. (DA=12% of Basic salary and HRA
= 30% of Basic salary) (Use appropriate manipulators to display
employee information in given format :- Emp_Id and Emp_Name should
be left justified and Basic_Salary, HRA, DA, Gross salary Right
justified with a precision of two digits)
Q.8B) Create a class Date containing members as:
- dd
- mm
- yyyy
Write a C++ program for overloading operators >> and << to accept and
display a Date also write a member function to validate a date.
8A)
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class emp
{
int eid;
float bs,hra,da,gs;
char name[10];
public:
void accept()
{
cout<<"enter id";
cin>>eid;
cout<<"enter name";
cin>>name;
cout<<"enter bs";
cin>>bs;
}
void display()
{
cout<<"\n eid="<<eid<<"\n
name="<<name<<"\n bssic salary = "<<bs;
cout<<"\n HRA = "<<(bs*0.30);
cout<<"\n DA = "<<(bs*0.12);
cout<<"\n Gross Salary = "<<(bs-
((bs*0.12)+(bs*0.30)));
}
};
void main()
{
emp ob;
clrscr();
ob.accept();
ob.display();
getch();
}
8B)
#include<iostream.h>
#include<conio.h>
class date
{
int dd,mm,yyyy;
public:
friend ostream &operator<<(ostream &out, date &dboj);
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
return 0;
}
Q.9A) Write a C++ program to create a class Person which contains data
members as P_Name, P_City, P_Contact_Number. Write member functions
to accept and display five Persons information. Design User defined
Manipulator to print P_Contact_Number. (For Contact Number set right
justification, maximum width to 10 and fill remaining spaces with
‘*’)
Q.9B) Create two base classes Learning_Info( Roll_No, Stud_Name, Class,
Percentage) and Earning_Info(No_of_hours_worked, Charges_per_hour). Derive
a class Earn_Learn_info from above two classes. Write necessary member
functions to accept and display Student information. Calculate total money
earned by the student. (Use constructor in derived class)
9A)
#include<iostream.h>
#include<conio.h>
//#include<manip.h>
class person
{
char p_name[20],p_city[10];
long int p_c_no;
public:
void getdata()
{
cout<<"\n enter person name\t";
cin>>p_name;
cout<<"\n enter persons city\t";
cin>>p_city;
cout<<"enter person contact no\t";
cin>>p_c_no;
}
void display()
{
cout<<"\n\n*************OUTPUT************
******\n";
cout<<"\nperson name =\t"<<p_name;
cout<<"\nperson city =\t"<<p_city;
//cout<<"\npersons contact number
is\t"<<p_c_no;
cout.width(10);
cout.fill('*');
cout<<p_c_no;
//cout<<cout.setw(10)<<p_c_no;
}
};
void main()
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
{
int i;
clrscr();
person p[5];
for(i=0;i<1;i++)
{
p[i].getdata();
}
for(i=0;i<1;i++)
{
p[i].display();
}
getch();
}
9B)
#include<iostream.h>
#include<conio.h>
class learning_info
{
int roll;
char sname[20],class1[20];
float per;
public:
void accept()
{
cout<<"\n enter the roll no,name ,class,per=";
cin>>roll>>sname>>class1>>per;
}
void display()
{
cout<<"\n roll no="<<roll<<"\n name="<<sname<<"\n
class="<<class1<<"\n percentage="<<per;
}
};
class earning_info
{
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
int noh;
float cph;
public:
void accept1()
{
cout<<"\n enter the number of hours and chargers per hours=";
cin>>noh>>cph;
}
void display1()
{
cout<<"\n no of hours="<<noh<<"\n chargers per hours="<<cph;
}
void calculate()
{
cout<<"\n total earning money="<<noh*cph;
}
};
class earn_learn: public learning_info,public earning_info
{
public:
void accept2()
{
accept();
accept1();
}
void display2()
{
display();
display1();
calculate();
}
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
};
int main()
{
clrscr();
earn_learn eobj;
eobj.accept2();
eobj.display2();
getch();
return 0;
}
Q.11A) Write a C++ program to find area and volume of cylinder using
Inline function.
Q.11B) Create a class College containing data members as College_Id,
College_Name,
Establishment_year, University_Name. Write a C++ program with
following member functions:
i. To accept ‘n’ College details
ii. To display College details of a specified University
iii. To display College details according to a specified
establishment year
(Use Array of Object and Function overloading)
11A)
#include<iostream.h>
#include<conio.h>
#define pi 3.14
class cylinder
{
float r,h;
public:
void getdata()
{
cout<<"\n Enter radius and height=";
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
cin>>r>>h;
}
inline void area()
{
cout<<"\n area of cylinder="<<2*pi*r*h;
}
inline void volume()
{
cout<<"\n volume of cylinder="<<pi*r*r*h;
}
};
int main()
{
clrscr();
cylinder cobj;
cobj.getdata();
cobj.area();
cobj.volume();
getch();
return 0;
}
11B)
#include<conio.h>
#include<iostream.h>
#include<string.h>
class college
{
int id,n,yr;
char name[10],uname[10];
public:
void accept()
{
cout<<"\n Enter id : ";
cin>>id;
cout<<"\n Enter name : ";
cin>>name;
cout<<"\n Enter univercity name : ";
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
cin>>uname;
cout<<"\n Enter year : ";
cin>>yr;
void display()
{
cout<<"\n id = "<<id<<"\n name = "<<name<<"\n Univercity name =
"<<uname<<"\n year = "<<yr<<endl;
}
void main()
{
int n,yr,a;
college ob[10];
char uni[10];
clrscr();
cout<<"enter no of college";
cin>>n;
for(int i=0;i<n;i++)
{
ob[i].accept();
}
for(i=0;i<n;i++)
{
ob[i].display();
}
cin>>uni;
int cnt=0;
for(i=0;i<n;i++)
{
a=ob[i].display(uni);
if(a==1)
cnt++;
}
if(cnt==0)
cout<<"\n Univercity name is NOT found "<<endl;
getch();
}
13A)
#include<iostream.h>
#include<conio.h>
class calculate
{
float r_cn,r_s,side;
int r_c;
public:
r_c=r;
side=s;
cout<<"\nArea of cone
=\t\t"<<3.14*r_c*side;
}
void area(float r)
{
r_s=r;
cout<<"\nArea of sphere
=\t"<<4*3.14*r_s*r_s;
}
void area(int r)
{
r_c=r;
cout<<"\nArea of circle
=\t"<<3.14*r_c*r_c;
}
};
void main()
{
float r_cone,side;
int r_circle;
float sp;
clrscr();
calculate c;
cout<<"\nEnter radius of cone\t";
cin>>r_cone;
cout<<"\nEnter side of cone\t";
cin>>side;
cout<<"\nEnter radius of sphere\t";
cin>>sp;
cout<<"\nEnter radius of circle\t";
cin>>r_circle;
c.area(r_cone,side);
c.area(sp);
c.area(r_circle);
getch();
}
13B)
#include<iostream.h>
#include<conio.h>
class matrix
{
public:
int r,c,a[10][10],i,j;
void getdata()
{
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
matrix()
{}
matrix(int row,int column)
{
r=row;
c=column;
}
friend matrix operator*(matrix,matrix);
};
matrix operator*(matrix obj,matrix obj1)
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
{
int i,j,k,sum;
if(obj.c==obj1.r)
{
matrix k1(obj.r,obj1.c);
for(i=0;i<obj.r;i++)
{
//cout<<endl;
for(j=0;j<obj1.c;j++)
{
//k.a[i][j]=0;
sum=0 ;
for(k=0;k<obj.c;k++)
{
sum=sum+obj.a[i][k] *
obj1.a[k][j];
}
k1.a[i][j]=sum;
}
}
return k1;
}
else
{
cout<<"multipliction is not possible";
matrix k(0,0);
return k;
}
}
void main()
{
clrscr();
matrix m1,m2,m3;
m1.getdata();
m2.getdata();
cout<<"\n first matrix is :";
m1.display();
cout<<"\n 2nd matrix is : ";
m2.display();
m3=m1*m2;
cout<<"\n Transpose of 1st matrix is : ";
-m1;
cout<<"\n mutiplication of matrix is : \n";
m3.display();
getch();
}
Q.14A) Write a C++ program to create a class Book which contains data
members as B_Id, B_Name, B_Author, B_Publication. Write member
functions to accept and display Book information also display Count
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
int book::cnt;
void main()
{
clrscr();
book b[20];int n;
cout<<"\nEnter no f Books : ";
cin>>n;
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
for(int i=0;i<n;i++)
b[i].getdata();
cout<<"\n Book Information are : \n \n";
for( i=0;i<n;i++)
b[i].display();
b[i-1].no_of_book();
getch();
}
14B)
#include<iostream.h>
#include<conio.h>
class shape
{
public:
virtual void accept()=0;
virtual void area()=0;
};
void area()
{
cout<<"\n Area of rectangle="<<l*b;
}
};
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
void area()
{
cout<<"\n Area of triangle="<<0.5*b*h;
}
};
void main()
{
triangle t;
circle c;
rectangle r;
shape *ptr;
clrscr();
ptr=&t;
ptr->accept();
ptr->area();
ptr=&c;
ptr->accept();
ptr->area();
ptr=&r;
ptr->accept();
ptr->area();
getch();
}
Q.15B) Write a C++ program to create a class which contains two data
members. Write member functions to accept display and swap two
entered numbers using call by reference.
Q.15B) Create a base class Student(Roll_No, Name, Class) which
derives two classes Internal_Marks(IntM1, IntM2, IntM3, IntM4,
IntM5) and External_Marks(ExtM1 ExtM2, ExtM3, ExtM4, ExtM5). Class
Result(T1, T2, T3, T4, T5) inherits both Internal_Marks and
External_Marks classes. (Use Virtual Base Class)
Write a C++ menu driven program to perform the following functions:
i. To Accept and display student details
ii. Calculate Subject wise total marks obtained. Check
whether student has passed in Internal and External
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
15B)
#include<iostream.h>
#include<conio.h>
#include<string.h>
class student
{
protected:
int rno;
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
char name[10],cls[10];
public:
void accept()
{
cout<<"\n Enter roll no if
sudent : ";
cin>>rno;
cout<<"\n Enter the name
of student :";
cin>>name;
cout<<"\n Enter the class
of student :";
cin>>cls;
}
void display()
{
cout<<"\n Roll no.
:"<<rno<<"\n Name :"<<name<<"\n class : "<<cls<<endl;
}
};
class Internal_Mark:public virtual student
{
protected:
int i_mark[6];
public:
int internal_mark()
{ int i;
cout<<"\n Enter the 6
subjects marks :";
for(i=0;i<6;i++)
{ cout<<"subj
ect "<<i+1<<" : ";
cin>>i_mar
k[i];
}
for(i=0;i<6;i++)
{ if(i_mark[i
]>20)
return 1;
}
return 0;
}
void i_display()
{
cout<<"\n Internal marks
is : \n ";
for(int i=0;i<6;i++)
{
cout<<"sub
ject "<<i+1<<"\t"<<i_mark[i]<<endl;
}
}
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
};
class External_Mark:public virtual student
{
protected:
int e_mark[6];
public:
int external_mark()
{ int i;
cout<<"\n Enter the 6
subjects External marks :";
for(i=0;i<6;i++)
{ cout<<"\n
subject "<<i+1<<" : ";
cin>>e_mar
k[i];
}
for(i=0;i<6;i++)
{ if(e_mark[i
]>80 || e_mark[i]<32)
return 1;
}
return 0;
}
void e_display()
{
cout<<"\n eXternal marks
are : \n ";
for(int i=0;i<6;i++)
{
cout<<"sub
ject "<<i+1<<"\t"<<e_mark[i]<<endl;
}
}
};
total[i]=i_mark[i]+e_mark[i];
}
}
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
void dis_res()
{
display();
i_display();
e_display();
cout<<"Total marks : \n ";
for(int i=0;i<6;i++)
{cout<<"subject
"<<i+1<<"\t"<<total[i]<<endl;}
};
int main()
{
clrscr();
int n,ch,a,b;
result obj;
do
{
cout<<"\n 1.student info \n 2.Internal mark \n 3.Extranal
mark \n 4. Result \n 0. exit";
cout<<"\n Enter your choice : ";
cin>>ch;
switch(ch)
{ case 1: obj.accept();
break;
case 2:
a=obj.internal_mark();
break;
case 3:
b=obj.external_mark();
break;
case 4: if(a==0 && b==0)
{obj.cal_r
es();
obj.dis_re
s();}
else
cout<<"Fail";
break;
case 0: break;
default: cout<<"\n Invalid
choice : ";
}
}while(ch!=0);
getch();
}
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
Q.16A) Write a C++ program to accept ‘n’ numbers from user through
Command Line Argument. Store all positive and negative numbers in
two different arrays. Display contents both arrays.
Q.16B) Define a class Product that contains data member as Prod_no,
Prod_Name, Prod_Price. Derive a class Discount(discount_in_Percentage)
from class Product. A Customer buys ‘n’ products. Accept quantity for each
product , calculate Total Discount and accordingly generate Bill. Display
the bill using appropriate Manipulators.
16A)
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main(int argc,char *argv[])
{
int pos[20],neg[20],n,j=0,k=0;
clrscr();
for(int i=1;i<argc;i++)
{
n=atoi(argv[i]);
if(n>=0)
{
pos[k]=n;
k++;
}
else
{
neg[j]=n;
j++;
}
}
getch();
}
16B)
#include<iostream.h>
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
#include<conio.h>
#include<iomanip.h>
class Product
{ public:
int no;
char pname[20];
float price;
public :
void accept()
{ cout<<"\n Enter product id : ";
cin>>no;
cout<<"\n Enter product name : ";
cin>>pname;
cout<<"\n Enter product price : ";
cin>>price;
}
};
void main()
{
Discount ob[10];
int i,n,total=0,discnt=0;
char cname[20];clrscr();
cout<<"\n Enter name of customer : ";
cin>>cname;
cout<<"\n Enter no product to be puraches : ";
cin>>n;
for(i=0;i<n;i++)
{
ob[i].accept();
ob[i].accept_D();
}
cout<<"\n **********YOUR BILL**************\n";
cout<<"\n Name of customer : "<<cname<<endl;
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
cout<<setiosflags(ios::left)<<setw(15)<<"Product name
"<<setw(10)<<"Price"<<setiosflags(ios::right)<<setw(10)<<"Discount"<<endl;
for(i=0;i<n;i++)
{
ob[i].display();
total=total+ob[i].price;
discnt=discnt+((ob[i].price * ob[i].d)/100);
}
cout<<"\n=====================================\n";
cout<<"Total : ";
cout<<setw(25)<<setiosflags(ios::right)<< total-discnt;
getch();
}
void display()
{
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
cout<<"\nrno = "<<rno;
cout<<"\nName = "<<name;
cout<<"\nPercantage = "<<per<<"%";
if(per>=70&&per<=100)
cout<<"\nDistinction";
else if(per<70&&per>=60)
cout<<"\n1st class";
else if(per<60&&per>=50)
cout<<"\n2nd class";
else if(per<50&&per>40)
cout<<"\npass class";
else
cout<<"\nfail";
cout<<"\n=================================
";
}
};
void main()
{
int n,i;
student ob[10];
clrscr();
cout<<"enter no of students";
cin>>n;
for(i=0;i<n;i++)
{
ob[i].accept();
}
for(i=0;i<n;i++)
{
ob[i].display();
}
getch();
}
17B)
#include<iostream.h>
#include<conio.h>
class distance
{
public:
int km,m;
void getdata()
{
cout<<"enter distance in kilometer\t";
cin>>km;
cout<<"enter distance in meters\t";
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
cin>>m;
}
void display()
{
cout<<"entered distance is\t";
cout<<km<<"."<<m;
cout<<endl;
}
void operator+=(distance d)
{
int kilometer=0,meter=0;
kilometer=km+d.km;
meter=m+d.m;
if(meter>=1000)
{
kilometer=km+d.km+(meter/1000);
meter=meter%1000;
}
cout<<"\naddition of two distances is\t"<<kilometer<<"."<<meter;
}
void operator>(distance d)
{
if(km>d.km)
{
cout<<"\ngreater distance is\t"<<km<<"."<<m;
}
else
{
cout<<"\ngreater distance is\t"<<d.km<<"."<<d.m;
}
}
};
void main()
{
clrscr();
distance d,d1;
d.getdata();
d1.getdata();
d.display();
d1.display();
d+=d1;
d>d1;
getch();
}
Q.22A) Write the definition for a class called ‘point’ that has x & y
as integer data members. Overload the assignment operator (=) to
copy one object to another. (Use Default and parameterized
constructor to initialize the appropriate objects)
Write a C++ program to illustrate the use of above class.
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
void display()
{
cout<<"\nx = "<<x<<"\t y = "<<y;
}
};
void main()
{
point ob1(100,200),ob2;
int n,m;
clrscr();
//cin>>m;
ob1.display();
//ob2.display();
ob2=ob1;
cout<<"\nAfter overload = operator .\n";
ob2.display();
getch();
}
22B)
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class conversion
{
public:
virtual void accept1()=0;
virtual void accept2()=0;
virtual void convert1()=0;
virtual void convert2()=0;
};
class weight:public conversion
{
public:
float gm,kgm;
void accept1()
{
cout<<"Enter grams to convert : ";
cin>>gm;
}
void accept2()
{
cout<<"Enter kilograms to convert : ";
cin>>kgm;
}
void convert1()
{
cout<<"After conversion gm = "<<gm/1000<<" kgm\n";
}
void convert2()
{
cout<<"After conversion kgm = "<<kgm*1000<<" gm\n";
}
};
float ml,ltr;
void accept1()
{
cout<<"\n Enter mililiter to convert : ";
cin>>ml;
}
void accept2()
{
cout<<"\n Enter liter to convert : ";
cin>>ltr;
}
void convert1()
{
cout<<"After conversion ml = "<<ml/1000<<" ltr\n";
}
void convert2()
{
cout<<"After conversion ltr = "<<ltr*1000<<" ml\n";
}
};
void main()
{
int ch;
weight w;
volume v;
currency c;
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
clrscr();
do
{
cout<<"\nEnter your choice\n";
cout<<"1.weight\t2.volume\t3.currency\t4.exit\n";
cin>>ch;
switch(ch)
{
case 1: int ch1;
cout<<"Enter your choice to convert weight\n";
cout<<"1.gm to kgm\t2.kgm to gm \n";
cin>>ch1;
if(ch1==1)
{
w.accept1();
w.convert1();
break;
}
else if(ch1==2)
{
w.accept2();
w.convert2();
break;
}
else
{
cout<<"wrong choice";
break;
}
getch();
}
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class sumdata
{
public:
void sum(int a,int b)
{
int c;
c=a+b;
cout<<"\n Addition = "<<c;
}
};
void main()
{
int a,b,j,k[19];
sumdata ob;
float x,y,z;
clrscr();
cout<<"\n Enter 2 numbers";
cin>>a;
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
cin>>b;
ob.sum(a,b);
cout<<"\n How many numbers you want to enter";
cin>>j;
ob.accept(k,j);
ob.sum(k,j);
cout<<"\n Enter 3 float values";
cin>>x;
cin>>y;
cin>>z;
ob.sum(x,y,z);
getch();
}
24B)
#include<iostream.h>
#include<conio.h>
class class2;
class class1
{
float a;
public:
void accept()
{
cout<<"\n Enter number : ";
cin>>a;
}
void display()
{
cout.setf(ios::left,ios::adjustfield);
cout.width(20);
cout<<"\n a="<<a;
}
friend void swap(class1 &,class2 &);
};
class class2
{
float b;
public:
void accept()
{
cout<<"\n Enter number : ";
cin>>b;
}
void display()
{
cout.setf(ios::left,ios::adjustfield);
cout.width(20);
cout<<"\n b="<<b;
}
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
void main()
{
class1 ob1;
class2 ob2;
clrscr();
ob1.accept();
ob2.accept();
ob1.display();
ob2.display();
swap(ob1,ob2);
cout<<"\n Ater swapping :\n";
ob1.display();
ob2.display();
getch();
}
#include<conio.h>
class Clock
{
int h,m,s,sec;
public :
void setclock(int hr,int min,int sec)
{
h=hr;
m=min;
s=sec;
}
void showclock()
{
cout<<"\n"<<h<<":"<<m<<":"<<s;
}
void tick()
{
cout<<"\n Enter sec to be incremented : ";
cin>>sec;
s=s+sec;
if(s>=60)
{ m=m+s/60;
s=s%60;
if(m>=60)
{
h=h+m/60;
m=m%60;
}
}
}
};
void main()
{
Clock c;
int hr,min,sec;
cout<<"\n Enter hr : ";
cin>>hr;
cout<<"\n Enter min : ";
cin>>min;
cout<<"\n Enter sec : ";
cin>>sec;
c.setclock(hr,min,sec);
c.showclock();
c.tick();
c.showclock();
getch();
}
25B)
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
#include<conio.h>
#include<iostream.h>
#include<string.h>
class person
{
char name[10],city[10],mno[12];
public:
void accept()
{
cout<<"\n Enter name : ";
cin>>name;
cout<<"\n Enter city : ";
cin>>city;
cout<<"\n Enter mob no : ";
cin>>mno;
}
void display()
{
cout<<"\n Name of person = "<<name;
cout<<"\n city = "<<city<<"\n mobile no = "<<mno;
cout<<"\n=======================================";
}
};
void main()
{
int n,i,cnt=0,ans;
char sname[20],mbno[12];
person ob[20];
clrscr();
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
for(i=0;i<n;i++)
{
ob[i].display();
}
getch();
}
27A)
#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;
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
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();
}
27B)
#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;
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
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();
}
Q.30A) Write a C++ program to sort integer and float array elements
in ascending order by using function overloading.
30A)
#include<iostream.h>
#include<conio.h>
class sorting
{
public:
double a[10];
int n,i;
- public:
void sort(int [],int);
void sort(float[],int);
};
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1
];
a[j+1]=tem
p;
}//if
}//2nd for
} //1st for
}
void main()
{
int n,i;
int a[10];float a1[10];
sorting s1;
clrscr();
cout<<"\nEnter how many element :";
cin>>n;
for(i=0;i<n;i++)
{ cout<<"\nEnter element";
cin>>a[i];
}
s1.sort(a,n);
cout<<"\Sorted element For integer array: \n";
for(i=0;i<n;i++)
{
cout<<"\t"<<a[i];
}
for( i=0;i<n;i++)
{ cout<<"\n Enter element :";
cin>>a1[i];
}
s1.sort(a1,n);
cout<<"\Sorted element For float array: \n";
for(i=0;i<n;i++)
{
cout<<"\t"<<a1[i];
}
getch();
}
30B)
#include<iostream.h>
#include<conio.h>
class fraction
{
public:
int num,den;
fraction()
{
num=0;
den=0;
}
fraction(int n,int d)
{
num=n;
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
den=d;
}
void display()
{
cout<<num<<"/"<<den;
cout<<endl;
}
fraction operator++() //pre increment
{
num=den+num;
den=den;
return *this;
}
fraction operator--() //pre decrement
{
num=den-num;
den=den;
return *this;
}
fraction operator++(int) //post increment
{
fraction temp=*this;
num=num+den;
den=den;
return temp;
}
fraction operator--(int) //post decrement
{
fraction temp=*this;
num=num-den;
den=den;
return temp;
}
friend fraction operator*(fraction,fraction);
};
fraction operator*(fraction f1,fraction f2)
{
fraction temp;
temp.num=f1.num*f2.num;
temp.den=f1.den*f2.den;
return temp;
}
void main()
{
clrscr();
fraction f1(5,10),f2(15,20),f4(25,30),f5(35,40);
f1.display();
f2.display();
fraction f3=f1*f2;
cout<<"multiplication of fraction is";
f3.display();
cout<<"pre increment is";
NITIN KUMAR
SYBBA(CA)
CPP PROGRAMS
fraction f6=++f1;
f6.display();
cout<<"post increment is";
fraction f7=f2++;
f7.display();
cout<<"pre decrement is";
fraction f8=--f4;
f8.display();
cout<<"post decrement is";
fraction f9=f5--;
f9.display();
getch();
}