Assignment C++
Assignment C++
*********************************************************************
#include <iostream.h>
#include<stdio.h>
#include<conio.h>
int main()
int count,number;
cin>>number;
cin >> a;
total = total + a;
cout << "The average of the data entered is " << average << endl;
return 0;
}
Program Even Odd
****************************************************************
#include<iostream.h>
#include<conio.h>
int main()
int number;
clrscr();
cin>>number;
if(number%2==0)
else
getch();
return 0;
}
Program for show the result using multiple inheritance
#include<iostream.h>
#include<conio.h>
class marksheet
private:
char name[20];
int rn;
char course[10];
public:
void getdata();
void showdata();
};
class marks
public:
int phy;
int comp;
int math;
public:
void getdata();
void showdata();
};
{
private:
int total;
int percentage;
public:
void getdata();
void display();
void marksheet::getdata()
cin>>name;
cin>>rn;
cin>>course;
void marksheet::showdata()
cout<<"\n Rollno:"<<rn;
cout<<"\n Class:"<<course;
void marks::getdata()
cin>>comp;
cin>>math;
void marks::showdata()
void result::getdata()
marksheet::getdata();
marks::getdata();
total=phy+comp+math;
percentage=total/3;
cout<<"\n Percentage:"<<percentage;
if(percentage>60)
else
if(percentage<60&&percentage>50)
if(percentage<45&&percentage>35)
else
void result::display()
marksheet::showdata();
marks::showdata();
cout<<"\n percentage:"<<percentage;
void main()
clrscr();
result g1;
g1.getdata();
g1.display();
getch();
}
Simple program for result
#include<conio.h>
#include<iostream.h>
void main()
char name[20];
char clas[]10;
int rollno;
float sub1,sub2,sub3,sub4,sub5;
double total;
float per;
total=0;
clrscr();
cin>>name;
cin>>clas;
cin>>rollno;
cin>>sub1;
cin>>sub2;
cout<<"Enter the no.in third subject :";
cin>>sub3;
cin>>sub4;
cin>>sub5;
total= (sub1+sub2+sub3+sub4+sub5 );
cout<<"\n total:"<<total;
per=(total/500)*100;
if(per>=60)
else if((per<60)&&(per>=50))
else if ((per<50)&&(per>=40))
{
Generate random number between two specified numbers
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int count=1;
while(count<=15)
cout<<"\t"<<count;
count=count+2;
getch();
return 0;
else if (per<40)
}
getch();
************************************************************************
#include<iostream.h>
#include<conio.h>
void main()
int x,y;
cin>>x;
cin>>y;
swap(x,y);
cout<<"\n x:"<<x;
cout<<"\n y:"<<y;
getch();
int t;
t=a;
a=b;
b=t;
Velocity program
#include<iostream.h>
#include<stdio.h>
#include<math.h>
int main()
cin>>time;
acceleration = 3-0.000062*pow(velocity,2);
cout<<"Velocity: "<<velocity<<endl;
cout<<"Acceleration: "<<acceleration<<endl;
return 0;
}
Velocity program
#include<iostream.h>
#include<stdio.h>
#include<math.h>
int main()
cin>>time;
cin>>displacement;
velocity = displacement/time;
return 0;
}
Program to check number entered is greater
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
int main()
int x,y,z,large;
cin>>x>>y>>z;
if(x>y)
if(x>z)
large=x;
else
large=z;
else if(y>z)
large=y;
else
large=z;
getch();
return 0;
}
Program to write the sum of positive and negative integers
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
int main()
int x,y,num,sum=0;
cin>>x;
for(y=1;y<=x;y++)
cin>>num;
if(num<0)
continue;
sum=sum+num;
getch();
return 0;
}
Program to add two prime numbers
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int main()
clrscr();
//int sum=0;
for(int j=2;j<=i;j++)
if(i%j==0 )
break;
if(i==j)
// sum=sum+i;