C++ Record Output and Program
C++ Record Output and Program
OUTPUT:
#include<iostream.h>
#include<conio.h>
class books
{
char title[30];
float price ;
public:
void getdata();
void putdata();
};
void books :: getdata()
{
cout<<"Title:";
cin>>title;
cout<<"Price:";
cin>>price;
}
void books :: putdata()
{
cout<<"Title:"<<title<< "\n";
cout<<"Price:"<<price<< "\n";
}
const int size=3;
int main()
{
clrscr();
books book[size];
for(int i=0;i<size;i++)
{
cout<<"Enter details of the book "<<(i+1)<<"\n";
book[i].getdata();
}
for(i=0;i<size;i++)
{
cout<<"\nBook "<<(i+1)<<"\n";
book[i].putdata();
}
return 0;
}
OUTPUT:
#include<iostream.h>
#include<conio.h>
class account
{
private:
int acc_no;
double balance;
static double rate;
public:
void read()
{
cout<<"\nEnter account number = ";
cin>>acc_no;
cout<<"\n Enter the Balance =";
cin>>balance;
}
void show()
{
cout<<"\nAccount no = "<<acc_no<< "\t";
cout<<"Interest = "<<rate<<"\t";
cout<<"Balance ="<<balance;
}
void qtr_rate_cal()
{
double interest=(balance*rate*0.25);
balance=balance+interest;
}
};
double account::rate=0.05;
int main()
{
clrscr();
account a1,a2;
cout<<"Enter customer 1 information \n";
a1.read();
cout<<"Enter customer 2 information \n";
a2.read();
a1.qtr_rate_cal();
a2.qtr_rate_cal();
a1.show();
a2.show();
getch();
return 0;
}
OUTPUT:
#include<iostream.h>
#include<conio.h>
inline int add(int x, int y)
{
return x+y;
}
inline int mul(int p, int q)
{
return p*q;
}
inline double div(int m , int n)
{
return m/n;
}
void main()
{
int x,y;
clrscr();
cout<<"Enter the Values :\n";
cin>>x>>y;
cout<<"Sum ="<<add(x,y)<<endl;
cout<<"Multiplication = "<<mul(x,y)<<endl;
cout<<"Division = "<<div(x,y)<<endl;
getch();
}
OUTPUT:
#include<iostream.h>
#include<conio.h>
class mark;
class info
{
private:
char name[30];
int reg;
public:
void getdata()
{
cout<<"Enter the name:\n";
cin>>name;
cout<<"Enter the register:\n";
cin>>reg;
}
friend void print(info f, mark k);
};
class mark
{
private:
int m1,m2,m3;
public:
void getdata()
{
cout<<"Enter the marks:\n";
cin>>m1>>m2>>m3;
}
friend void print(info f, mark k);
};
void print(info f, mark k)
{
cout<<"Name :"<<f.name<<endl;
cout<<"Register number :"<<f.reg<<endl;
cout<<"Mark 1 :"<<k.m1<<endl;
cout<<"Mark 2 :"<<k.m2<<endl;
cout<<"Mark 3 :"<<k.m3<<endl;
cout<<"Total Mark :"<<k.m1+k.m2+k.m3<<endl;
if(k.m1>=40 && k.m2>=40 && k.m3>=40)
cout<<"Result is pass"<<endl;
else
cout<<"Result is fail"<<endl;
}
void main()
{
info f1;
mark k1;
clrscr();
f1.getdata();
k1.getdata();
print(f1,k1);
getch();
}
OUTPUT:
OUTPUT:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
class student
{
private:
char regno[9];
char name[25];
int age;
public:
void getdata();
void display();
};
void student::getdata()
{
cout<<"\n Enter the Register Number:";
cin>>regno;
cout<<"Enter the name:";
gets(name);
cout<<"Enter the age:";
cin>>age;
}
void student::display()
{
cout<<"\nStudent Personal Details";
cout<<"\n________________________";
cout<<"\n Register Number:"<<regno;
cout<<"\nName :"<<name;
cout<<"\nAge :"<<age;
}
class sports:public student
{
private:
char sportsname[25];
float score;
public:
void getdata()
{
student::getdata();
cout<<"\n Enter the sports name:";
gets(sportsname);
cout<<"Enter the sports score:";
cin>>score;
}
void display()
{
student::display();
cout<<"\n\nSports Details";
cout<<"\n\n______________";
cout<<"\n Sports NAme:"<<sportsname;
cout<<"\nSports Score:"<<score;
}
};
void main()
{
sports s1;
clrscr();
s1.getdata();
s1.display();
getch();
}
OUTPUT:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
class student
{
private:
int regno;
char name[25];
int age;
protected:
float boardexam;
public:
void getdata();
void display();
};
class entrance
{
protected:
float entper;
public:
void getdata();
void display();
};
class sports
{
protected:
float score;
public:
void getdata();
void display();
};
class result:public student,public entrance,public sports
{
private:
float totalscore;
public:
void getdata();
void calresult();
void display();
};
void student::getdata()
{cout<<"\n\tBase Class 1 -Student";
cout<<"\n\t=======================";
cout<<"\n Enter the Register Number:";
cin>>regno;
void entrance::display()
{
cout<<"\n\nBase Class2- Entrance";
cout<<"\n\n=====================";
cout<<"\n Entrance Exam Precentage:"<<entper;
}
void sports::getdata()
{
cout<<"\n\nBase Class3- Sports";
cout<<"\n\n=====================";
cout<<"\n EnterSports Score";
cin>>score;
}
void sports::display()
{
cout<<"\n\nBase Class3- Sports";
cout<<"\n\n=====================";
cout<<"\n Sports Score"<<score;
}
void result::getdata()
{
student::getdata();
entrance::getdata();
sports::getdata();
}
void result::calresult()
{
totalscore=boardexam+entper+score;
}
void result::display()
{
student::display();
entrance::display();
sports::display();
cout<<"\n\nDerived Class - Result";
cout<<"\n\n=====================";
cout<<"\n Total Score:"<<totalscore;
}
void main()
{
clrscr();
cout<<"\t\t******Multiple Inheritance***";
result s1;
s1.getdata();
s1.calresult();
s1.display();
getch();
}
OUTPUT:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class complex
{
int real;
float image;
public:
void getdata()
{
cout<<"\nenter the real part of the complex::";
cin>>real;
cout<<"\nenter the imaginary part of the complex::";
cin>>image;
}
void operator+(complex);
void operator-(complex);
};
void complex::operator+(complex c1)
{
complex temp;
temp.real=real+c1.real;
temp.image=image+c1.image;
if (temp.image>=0)
{
cout<<"\ncomplex no. after addition::";
cout<<temp.real<<"+"<<temp.image<<"i\n";
}
else
{
cout<<"\ncomplex no. after addition::";
cout<<temp.real<<temp.image<<"i\n";
}
}
void complex::operator-(complex c1)
{
complex temp;
temp.real = real-c1.image;
temp.image=image-c1.image;
if (temp.image>=0)
{
cout<<"\n complex no. after subtraction :: ";
cout<<"\ntemp.real"<<"+"<<temp.image<<"i\n";
}
else
{
cout<<"\ncomplexno.aftersubtraction::";
cout<<temp.real<<temp.image<<"i\n";
}
}
int main()
{
clrscr();
complex c1,c2;
int n;
do
{
cout<<"\n1. Inputdata for complex no. ";
cout<<"\n 2. Addition of complex no. ";
cout<<"\n3.Subtraction of complexno.";
cout<<"\n 4. Quit";
cout<<"\nEnter yourchoice::";
cin>>n;
switch(n)
{
case 1:
cout<<endl<<"\nEnter the data for First ComplexNo";
c1.getdata();
cout<<endl<<"\nEnter the data for seconds Complex No";
c2.getdata();
break;
case 2:
c1+c2;
break;
case 3:
c1-c2;
break;
case 4:
break;
}
}while(n!=4);
return 0;
}
OUTPUT:
#include<iostream.h>
#include<conio.h>
void area(int a)
{
int square=a*a;
cout<<"The Area Of Square Value is:"<<square<<endl;
}
void area(int l, int b)
{
int rectangle=l*b;
cout<<"The Area Of The Rectangle Value is:"<<rectangle<<endl;
}
void area(float r)
{
float circle=2.34*r*r;
cout<<"The Area of The Circle Value is:"<<circle<<endl;
}
void area(float le,float br)
{
float triangle=0.4*le*br;
cout<<"The Area Of the triangle value is:"<<triangle<<endl;
}
int main()
{
clrscr();
int a,b,l;
float r,le,br;
cout<<" "<<endl;
cout<<"AREA OF SHAPES USING FUNCTION OVERLOADING"<<endl;
cout<<" "<<endl;
cout<<"Enter one value for Square:";
cin>>a;
cout<<endl;
cout<<"Enter two value for Rectangle:";
cin>>b>>l;
cout<<endl;
cout<<"Enter one value for Circle:";
cin>>r;
cout<<endl;
cout<<"Enter two values for triangle:";
cin>>le>>br;
cout<<endl;
cout<<" "<<endl;
area(a);
area(l,b);
area(r);
area(le,br);
cout<<" "<<endl;
return 0;
}
OUTPUT: