C++ RECORD dgvc-2
C++ RECORD dgvc-2
COLLEGE (AUTONOMOUS)
ARUMBAKKAM, CHENNAI-600 106.
TABLE OF CONTENTS
1 SIMPLE INEREST
28.07.22
CALCAULATIONS
Ex.no : 01
Date : 28.07.22
AIM:
To demonstrate the usage of Simple interest
Calculations in C++ program.
PROGRAM:
#include <iostream.h>
#include <conio.h>
int main( )
{
clrscr( );
float p,r,t,si;
cout<<"enter principle amount:";
cin>>p;
cout<<"enter rate of interest:";
cin>>r;
cout<<"enter time period:";
cin>>t;
si=(p+r+t)/100;
cout<<"simple interest amount:"<<si<<endl;
return 0;}
OUTPUT:
RESULT:
Thus, finding Simple Interest Calculation using C++
Program is implemented and verified successfully.
Ex.no : 02
Date : 18.08.22
AIM:
To demonstrate the usage of Area and Perimeter of
Triangle in C++ program.
PROGRAM:
#include <iostream.h>
#include <math.h>
#include <conio.h>
class triangle
{
private:
float a,b,c,s,aa;
public:
void getdata();
float area();
float perimeter();
};
void triangle::getdata()
{
cout<<"enter the length of first sides:";
cin>>a;
cout<<"enter the length of second sides:";
cin>>b;
cout<<"enter the length of thrid sides:";
cin>>c;
}
float triangle::area()
{
s=(a+b+c)/2;
aa=sqrt(s*(s-a)*(s-b)*(s-c));
return aa;
}
float triangle::perimeter()
{
return(a+b+c);
}
void main()
{
clrscr();
triangle t;
float ar,pr;
t.getdata();
ar=t.area();
cout<<"area="<<ar<<endl;
pr=t.perimeter();
cout<<"perimeter="<<pr<<endl;
}
OUTPUT:
RESULT:
Thus, finding Area And Perimeter of Triangle using
C++ Program is implemented and verified successfully.
AVERAGE OF N NUMBERS
Ex.no : 03
Date : 27.08.22
AIM:
To demonstrate the usage of Average of N numbers in
C++ program.
PROGRAM:
#include <iostream.h>
#include <conio.h>
int main()
{
clrscr();
int n,i;
float num[100],sum=0.0,avg;
cout<<"enter the number of data:";
cin>>n;
while(n>100||n<=0)
{
cout<<"error!number should in range of 1 to 100:"<<endl;
cout<<"enter the number again:";
cin>>n;
}
for(i=0;i<n;i++)
{
cout<<i+1<<"enter the number:";
cin>>num[i];
sum+=num[i];
}
avg=sum/n;
cout<<"average="<<avg;
return 0;
}
OUTPUT:
RESULT:
Thus, finding Average of N Numbers using C++
Program is implemented and verified successfully.
FUNCTION OVERLOADING
Ex.no : 04
Date : 06.09.22
AIM:
To demonstrate the usage of Function Overloading in
C++ Program.
PROGRAM:
#include <iostream.h>
#include <conio.h>
void display(int var1,double var2)
{
cout<<"integer number:"<<var1;
cout<<" and double number:"<<var2;
}
void display(double var)
{
cout<<"double number:"<<var<<endl;
}
void display(int var)
{
cout<<"integer number:"<<var<<endl;
}
int main()
{
clrscr();
int a= 5;
double b= 5.5;
display(a);
display(b);
display(a,b);
return 0;
}
OUTPUT:
Integer Number: 5
Double Number: 5.5
Integer Number: 5 And Double Number: 5.5
RESULT:
Thus, finding Functoin Overloading using C++
Program is implemented and verified successfully.
OPERATOR OVERLOADING
Ex.no : 05
Date : 12.09.22
AIM:
To demonstrate the usage of Operator Overloading in
C++ program.
PROGRAM:
#include <iostream.h>
#include <conio.h>
class complex
{
float x,y;
public:
complex(){}
complex(float real,float imag)
{
x=real;
y=imag;
}
complex operator+(complex);
void display();
};
complex complex::operator+(complex c)
{
complex temp;
temp.x=x+c.x;
temp.y=y+c.y;
return(temp);
}
void complex::display()
{
cout<<x<<"+j"<<y<<"\n";
}
int main()
{
clrscr();
complex C1,C2,C3;
C1=complex(2.5,3.5);
C2=complex(1.6,2.7);
C3=C1+C2;
cout<<"c1=";C1.display();
cout<<"c2=";C2.display();
cout<<"c3=";C3.display();
return 0;}
OUTPUT:
C1= 2.5+j3.5
C2= 1.6+j2.7
C3= 4.1+j6.2
RESULT:
Thus, finding Operator Overloading using C++
Program is implemented and verified successfully.
QUADRATIC EQUATIONS
Ex.no : 06
Date : 12.09.22
AIM:
To demonstrate the usage of Quadratic Equations in
C++ program.
PROGRAM:
#include<iostream.h>
#include<math.h>
#include<conio.h>
int main()
{
clrscr();
float a,b,c,x1,x2,d,real,imaginary;
cout<<"Quadratic Equation : ax^2 + bx + c";
cout<<"\nEnter coefficient of a : ";
cin>>a;
cout<<"Enter coefficient of b : ";
cin>>b;
cout<<"Enter coefficient of c : ";
cin>>c;
d=b*b-4*a*c;
if(d>0)
{
cout<<"Roots are real and distinct";
x1=(-b + sqrt(d)) / (2*a);
x2=(-b - sqrt(d)) / (2*a);
cout<<"\nx1 = "<<x1;
cout<<"\nx2 = "<<x2;
}
else if(d==0)
{
cout<<"Roots are real and same";
x1=(-b + sqrt(d)) / (2*a);
cout<<"\nx1 = "<<x1;
cout<<"\nx2 = "<<x1;
}
else
{
cout<<"Roots are real and distinct";
real = -b/(2*a);
imaginary = sqrt(-d) / (2*a);
cout<<"\nx1 = "<<real<<"+"<<imaginary<<"i";
cout<<"\nx2 = "<<real<<"-"<<imaginary<<"i";
}
return 0;
}
OUTPUT:
RESULT:
Ex.no : 07
Date : 11.10.22
AIM:
To demonstrate the usage of Single Inheritance in C+
+ program.
PROGRAM:
#include <iostream.h>
class student
{
private:
char name[20];
int age;
char gender;
public:
void getdata();
void putdata();
};
void student::getdata()
{
cout<<"enter the name:";
cin>>name;
cout<<"enter the age:";
cin>>age;
cout<<"enter the gender:";
cin>>gender;
}
void student::putdata()
{
cout<<"name:"<<name<<"age:"<<age<<"gender:"<<gende
r<<endl;
}
class result:public student
{
private:
int totalmarks;
float perc;
char grade;
public:
void getresultinfo();
void putresultinfo();
};
void result::getresultinfo()
{
cout<<"enter the totalmarks:";
cin>>totalmarks;
perc=float(totalmarks*100/500);
if (perc>=80)
{
cout<<"distinstion";
}
else if (perc>=60)
{
cout<<"first class";
}
else if (perc>=50)
{
cout<<"second class";
}
else if (perc>=40)
{
cout<<"third class";
}
else;
{
cout<<"fail";
}
void result::putresultinfo()
{
cout<<"marks:"<<totalmarks<<"percentage:"<<perc<<"gra
de:"<<grade<<endl;
}
int main:
{
result r;
r.getdata();
r.putdata();
r.getresultinfo();
r.putresultinfo();
return 0;}
OUTPUT:
RESULT:
Ex.no : 08
Date : 18.10.22
AIM:
To demonstrate the usage of Virtual Function in
C++ program.
PROGRAM:
#include<iostream.h>
#include<conio.h>
class base
{
public:
virtual void print()
{
cout<<"print base class:"<<endl;
}
void show()
{
cout<<"show base class:"<<endl;
}
};
class derived:public base
{
public:
void print()
{
cout<<"print derived class:"<<endl;
}
void show()
{
cout<<"show derived class"<<endl;
}
};
int main()
{
clrscr();
base *bptr;
derived d;
bptr= &d;
bptr->print();
bptr->show();
return 0;
}
OUTPUT:
RESULT:
AIM:
To demonstrate the usage of Copying the content from
one file to another file in C++ program.
PROGRAM:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream fs;
ofstream ft;
string str;
char sourcefile[50], destinationfile[50];
cout << "Enter Source File with Extension: ";
gets(sourcefile);
fs.open(sourcefile);
if (!fs)
{
cout << "Error in Opening Source File...!!!";
exit(1);
}
gets(destinationfile);
ft.open(destinationfile);
if (!ft)
{
cout << "Error in Opening Destination File...!!!";
fs.close();
exit(2);
}
}
else
{
cout << "File Cannot Open...!!!";
}
cout << "\n\n Open Destination File and Check!!!\n";
fs.close();
ft.close();
}
OUTPUT :
RESULT:
Ex.no : 10
Date : 04.11.22
AIM:
To demonstrate the usage of Multiple Inheritance in
C++ program.
PROGRAM:
#include <iostream.h>
#include <conio.h>
class student
{
protected:
int rno,sum,i,marks[5];
public:
void detail()
{
cout<<"enter the roll no.:"<<endl;
cin>>rno;
cout<<"enter the marks of 5 subjects:"<<endl;
for (i=0;i<5;i++)
{
cin>>marks[i];
}
sum=sum+marks[i];
}
};
class sports
{
protected:
int s_mark;
public:
void get_mark()
{
cout<<"enter the sports mark:"<<endl;
cin>>s_mark;
}
};
class result:public student,public sports
{
int tot,avg;
public:
void display()
{
tot=sum+s_mark;
avg=tot/6;
cout<<"\n\n\t rollno.:"<<rno<<"\n\t total:"<<tot<<endl;
cout<<"\n\t average marks:"<<avg;
}
};
int main()
{
clrscr();
result r;
r.detail();
r.get_mark();
r.display();
return 0;
}
OUTPUT:
RESULT: