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

Mayurcpp

The document contains solutions to 5 questions asked in an exam. It includes C++ programs to create classes for students and sales data, perform operations on time, inherit from two base classes, and calculate areas using function overloading. The programs demonstrate class concepts like objects, methods, constructors, and inheritance through practical examples.

Uploaded by

Mayur Bamb
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Mayurcpp

The document contains solutions to 5 questions asked in an exam. It includes C++ programs to create classes for students and sales data, perform operations on time, inherit from two base classes, and calculate areas using function overloading. The programs demonstrate class concepts like objects, methods, constructors, and inheritance through practical examples.

Uploaded by

Mayur Bamb
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 11

NAME-: MAYUR PRADIP BAMB ROLL NO.

-:3209

Q1.write c++ program to create class student(rno,name,class).write neccesary function to accepet


student info. and display student info with its percentage.[use array of object]

#include<iostream.h>

#include<conio.h>

class student

public:

char name[10];

int rno; void disp()

cout<<"\n na

float per;

void accept()

cout<<"\n enter stud name=";

cin>>name;

cout<<"enter roll no.=";

cin>>rno;

cout<<"\n enter percentage=";

cin>>per;

me of student="<<name;

cout<<"\n percentage="<<per;

cout<<"\n roll no.="<<rno;

};
int main()

student ob[10];

int i,n;

clrscr();

cout<<"\n enter limit=";

cin>>n;

for(i=0;i<n;i++)

ob[i].accept();

for(i=0;i<n;i++)

ob[i].disp();

getch();

return 0;

NAME-: MAYUR PRADIP BAMB ROLL NO.-:3209

Q2.write c++ program create class sales contain salesman_name,product_name,sales_qty,target as


data member.if sales_quantity>target then commision is 25% of extra sales made plus 10% of
target and if sales_quantity==target then commision is 10% of target otherwise, commision=0. [use
array of object].

#include<iostream.h>

#include<conio.h>

class sales

public:

int sales_quantity,target;

char salesman_name[10],product_name[10];

float com;

void accept()

cout<<"\n enter salesman name=";

cin>>salesman_name;

cout<<"\n enter product name=";

cin>>product_name;

cout<<"\n enter sales quantity=";

cin>>sales_quantity;

cout<<"\n enter target=";

cin>>target;

void cal()

if(sales_quantity>target)

com=sales_quantity+(sales_quantity*0.25)+target+(target*0.10);

else if(sales_quantity==target)

com=target+(target*0.10);

else

com=0;
}

void disp()

cout<<"\n salesman name="<<salesman_name;

cout<<"\n product name="<<product_name;

cout<<"\n sales quantity="<<sales_quantity;

cout<<"\n target="<<target;

cout<<"\n commision="<<com;

};

int main()

sales ob[10];

int i,n;

clrscr();

cout<<"\n enter limit=";

cin>>n;

for(i=0;i<n;i++)

ob[i].accept();

for(i=0;i<n;i++)

ob[i].cal();

ob[i].disp();

getch();

return 0;

}
NAME-: MAYUR PRADIP BAMB ROLL NO.-:3209

Q3.write c++ program create class time (hours,minutes,second). perform following operations.

1]to read time

2]display time in format like hh:mm:ss

3]add two different times

[use object as argument].

#include<iostream.h>

#include<conio.h>

class time

public:

int h,m,s;

void accept();

void disp();

void add(time ob,time ob1);

};

void time::accept()
{

cout<<"\n enter the time in hours minutes second=";

cin>>h>>m>>s;

void time::disp()

cout<<"\n time="<<h<<":"<<m<<":"<<s;

void time::add(time ob,time ob1)

ob.s=ob.s+ob1.s;

if(ob.s>60)

ob.m++;

ob.s=ob.s-60;

ob.m=ob.m+ob1.m;

if(ob.m>60)

ob.h++;

ob.m=ob.m-60;

ob.h=ob.h+ob1.h;

if(ob.h>24)

ob.h=ob.h-24;

ob.disp();

}
int main()

time ob,ob1;

clrscr();

ob.accept();

ob1.accept();

ob.disp();

ob1.disp();

ob.add(ob,ob1);

getch();

return 0;

NAME-: MAYUR PRADIP BAMB ROLL NO.-:3209

Q4.create two base class learning_info(roll_no,stud_name,class,per) and


earning_info(no_of_hours_work,charges_per_hour) derived class earn_learn_info from above two
classes.write neccesary member function to accept and display student info. calculate total money
earn by student.[use constructor in derived class]

#include<iostream.h>
#include<conio.h>

class learning_info

public:

int rno;

float per;

char name[10],clas[10];

void accept()

cout<<"\n enter roll no=";

cin>>rno;

cout<<"\n enter name=";

cin>>name;

cout<<"\n enter class=";

cin>>clas;

cout<<"\n enter per=";

cin>>per;

void disp()

cout<<"\n roll no.="<<rno;

cout<<"\n name="<<name;

cout<<"\n class="<<clas;

cout<<"\n percentage="<<per;

};

class earning_info

public:
int no_of_hours_work,charges_per_hour;

void putdata()

cout<<"\n enter num of hours work=";

cin>>no_of_hours_work;

cout<<"\n enter charges per hour=";

cin>>charges_per_hour;

void cal()

int salary=no_of_hours_work*charges_per_hour;

cout<<"\n salary="<<salary;

};

class learn_earn_info:public learning_info,public earning_info

public:

learn_earn_info()

cout<<"\n student details are....";

};

int main()

learn_earn_info ob;

clrscr();

learn_earn_info();

ob.accept();

ob.putdata();
ob.disp();

ob.cal();

getch();

return 0;

NAME-: MAYUR PRADIP BAMB ROLL NO.-:3209

Q5.write c++ program to calculate area of cone,area of sphere,area of circle using function
overloading

#include<iostream.h>

#include<conio.h>

float area(float,float);

float area(int);

float area(float);

int main()

clrscr();

cout<<"\n area of cone="<<area(3.5f,4.5f);

cout<<"\n area of sphere="<<area(4);


cout<<"\n area of ciclr="<<area(4.5f);

getch();

return 0;

float area(float r, float h)

return (3.14*r*r*h)/3;

float area(int r)

return (4*3.14*r*r);

float area(float r)

return (3.14*r*r);

You might also like