/* Slip no 3_1: 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.*/
#include<iostream.h>
#include<conio.h>
class date
{
int
dd,mm,yy;
public:
date(int
d,int m,int y)
{
dd=d;
mm=m;
yy=y;
}
void
display()
{
cout<<"\ngiven
date is\t";
cout<<dd<<"-"<<mm<<"-"<<yy;
cout<<"\nAfter
formating date is\t";
switch(mm)
{
case
1:
cout<<"\n"<<dd<<"-Jan-"<<yy;
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<<"\nInvalid
month";
}
}
};
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();
}
/* Slip no : 3_2 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:
Build
a master table
Calculate
Total_marks and
grade */
#include<conio.h>
#include<string.h>
#include<iostream.h>
class student
{
protected:
int
rno;
char
name[10];
public:
void
accept()
{
cout<<"\nEnter
roll no if sudent : ";
cin>>rno;
cout<<"\nEnter
the name of student :";
cin>>name;
cout<<endl;
}
void
display()
{
cout<<"\nRoll
no : "<<rno<<"\t Name : "<<name<<endl;
}
};
class Academic_Mark:public
virtual student
{
protected:
int
mark1,mark2,mark3;
public:
void
accept_A()
{
cout<<"\nEnter
the 3 subject marks :";
cin>>mark1>>mark2>>mark3;
}
void
display_A()
{
cout<<"\nMarks
sub1 :"<<mark1<<"\nMarks sub2
:"<<mark2<<"\nMarks sub3 :"<<mark3;
}
};
class Extra_Activity : public
virtual student
{
protected:
int
mark;
public:
void
accept_E()
{
cout<<"\nEnter
Extra Activity mark :";
cin>>mark;
}
void
display_E()
{
cout<<"\nEnter
Extra activity mark :"<<mark<<endl;
}
};
class result: public
Academic_Mark,public Extra_Activity
{
public:
int
total;
char
grade[10];
float
per;
void
cal_res()
{
total=mark1+mark2+mark3+mark;
per=(total/3);
if(per>=70)
strcpy(grade,"distinction");
else
if(per<70
&& per>=60)
strcpy(grade,"A+");
else
if(per<60
&& per>=50)
strcpy(grade,"A");
else
if(per<50 && per>=40)
strcpy(grade,"B");
else
strcpy(grade,"Fail");
cout<<"\n
==============================";
cout<<"\nTotal
:"<<total<<"\nGrade :"<<grade<<endl;
}
};
void main()
{
clrscr();
int
n,ch;
result
obj;
do
{
cout<<"\n
1.student info \n 2.Academic mark \n 3.Extra activity mark \n 4.Result \n
0.Exit";
cout<<"\n
Enter your choice : ";
cin>>ch;
switch(ch)
{ case
1: obj.accept();
break;
case
2: obj.accept_A();
break;
case
3: obj.accept_E();
break;
case
4: obj.display();
obj.display_A();
obj.display_E();
obj.cal_res();
break;
case
0: break;
default:
cout<<"\n Invalid choice : ";
}
}while(ch!=0);
getch();
}
slips 3
Reviewed by Dinesh Varal
on
January 15, 2018
Rating:
No comments: