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

Assignment C++

C++ Assignment

Uploaded by

deju
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Assignment C++

C++ Assignment

Uploaded by

deju
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 16

*calculate the average for n numbers

*********************************************************************

#include <iostream.h>

#include<stdio.h>

#include<conio.h>

// This program calculates the average

int main()

int count,number;

float a, total, average;

cout<<"How many number you want :";

cin>>number;

for (count =1; count <=number; ++count)

cout << "Enter a number: ";

cin >> a;

total = total + a;

average = total /number;

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();

cout<<"\n Enter the number :";

cin>>number;

if(number%2==0)

cout<<"\nThe given number is Even";

else

cout<<"\n The given number is Odd";

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();

};

class result :public marksheet,public marks

{
private:

int total;

int percentage;

public:

void getdata();

void display();

void marksheet::getdata()

cout<<"\n Enter the name of the student:";

cin>>name;

cout<<"\n Enter the rollno:";

cin>>rn;

cout<<" \n Enter the class:";

cin>>course;

void marksheet::showdata()

cout<<"\n Name of the student:"<<name;

cout<<"\n Rollno:"<<rn;

cout<<"\n Class:"<<course;

void marks::getdata()

cout<<"Enter the marks of physics:";


cin>>phy;

cout<<"Enter the marks of computer:";

cin>>comp;

cout<<"Enter the marks of maths:";

cin>>math;

void marks::showdata()

cout<<"\n Marks in physics :"<<phy;

cout<<" \n Marks in computer :"<<comp;

cout<<"\n Marks in maths :"<<math;

void result::getdata()

marksheet::getdata();

marks::getdata();

total=phy+comp+math;

percentage=total/3;

cout<<"\n Total marks:"<<total;

cout<<"\n Percentage:"<<percentage;

if(percentage>60)

cout<<"\n **** First Division **** Excellent";

else

if(percentage<60&&percentage>50)

cout<<"\n *** Second Division *** Good";


else

if(percentage<45&&percentage>35)

cout<<"\n * Third Division * Keep It Up";

else

cout<<"\n Fail...!!!!!!!! WORK HARD DUDE";

void result::display()

marksheet::showdata();

marks::showdata();

cout<<" \n total: "<<total;

cout<<"\n percentage:"<<percentage;

void main()

clrscr();

result g1;

g1.getdata();

g1.display();

getch();

}
Simple program for result

#include<conio.h>

#include<iostream.h>

// simple program for percentage of marks

void main()

char name[20];

char clas[]10;

int rollno;

float sub1,sub2,sub3,sub4,sub5;

double total;

float per;

total=0;

clrscr();

cout<<"Enter your name :";

cin>>name;

cout<<"Enter your Class :";

cin>>clas;

cout<<"Enter your roll no :";

cin>>rollno;

cout<<"Enter the no.in first subject :";

cin>>sub1;

cout<<"Enter the no.in second subject :";

cin>>sub2;
cout<<"Enter the no.in third subject :";

cin>>sub3;

cout<<"Enter the no.in fourth subject :";

cin>>sub4;

cout<<"Enter the no.in fifth subject :";

cin>>sub5;

total= (sub1+sub2+sub3+sub4+sub5 );

cout<<"\n total:"<<total;

per=(total/500)*100;

if(per>=60)

cout<<"\n percentage marks:"<<per;

cout<<"\nYou get first division";

else if((per<60)&&(per>=50))

cout<<"\n percentage marks:"<<per;

cout<<"\nYou get second division";

else if ((per<50)&&(per>=40))

{
Generate random number between two specified numbers

#include<iostream.h>

#include<conio.h>

//generate random numbr between two specified number

void main()

clrscr();

int count=1;

cout<<"\n Random number betwwn 1 and 15"<<endl;

while(count<=15)

cout<<"\t"<<count;

count=count+2;

getch();

return 0;

cout<<"\n percentage marks:"<<per;

cout<<"\nYou get third division";

else if (per<40)

cout<<"\n percentage marks:"<<per;

cout<<"\nYou are fail";

}
getch();

Swapping using call by reference

************************************************************************

#include<iostream.h>

#include<conio.h>

//***Swapping the two variable using passing by refrence

void main()

int x,y;

void swap(int &,int &);

cout<<"\n enter the value of x:";

cin>>x;

cout<<"\n enter the value of y:";

cin>>y;

swap(x,y);

cout<<"\n x:"<<x;

cout<<"\n y:"<<y;

getch();

void swap(int &a,int&b)

int t;

t=a;
a=b;

b=t;

Velocity program

#include<iostream.h>

#include<stdio.h>

#include<math.h>

int main()

int time,velocity, acceleration;

cout<<"Please input time in seconds: \n";

cin>>time;

velocity = 0.00001* pow(time,3)-.00488* pow (time,2)+.75795*time+181.3566;

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()

int time,velocity, displacment;

cout<<"Please input time in seconds: \n";

cin>>time;

cout<<"Please input displacement of beam of light in Kms: \n";

cin>>displacement;

velocity = displacement/time;

cout<<"Velocity of beam of light: "<<velocity<<endl;

return 0;

}
Program to check number entered is greater

#include<stdio.h>

#include<conio.h>

#include<iostream.h>

// largest integer out three integer

int main()

int x,y,z,large;

cout<<"Enter three Intergers you want to check";

cin>>x>>y>>z;

if(x>y)

if(x>z)

large=x;

else

large=z;

else if(y>z)

large=y;

else

large=z;

cout<<"\n the largest number is "<<large;

getch();

return 0;

}
Program to write the sum of positive and negative integers

#include<stdio.h>

#include<conio.h>

#include<iostream.h>

//sum of integer out of negative and positive integer

int main()

int x,y,num,sum=0;

cout<<"Enter No.of the Intergers you want to sum";

cin>>x;

for(y=1;y<=x;y++)

cout<<"Enter the numbers:";

cin>>num;

if(num<0)

continue;

sum=sum+num;

cout<<"sum of positive integers:"<<sum;

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 i=2;i<=5;i++)

for(int j=2;j<=i;j++)

if(i%j==0 )

break;

if(i==j)

cout<<"prime numbers are:"<<i<<endl;;

// sum=sum+i;

// cout<<"sum of two prime numbers is:"<<sum<<endl;

You might also like