Top Banner
PROGRAMMING OF TRUBO C++ LANGUAGE Program No:1 (Addition of Two Numbers) # include<iostream.h> # include<conio.h> Void main (void) { Clrscr () ; Int a,b,c ; a=10; b=20; C= a+b Cout<<c; getch (); }
28

C++ assignment

Apr 14, 2017

Download

Education

Zohaib Ahmed
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: C++ assignment

PROGRAMMING OF TRUBO C++ LANGUAGE

Program No:1 (Addition of Two Numbers)# include<iostream.h>

# include<conio.h>

Void main (void)

{

Clrscr () ;

Int a,b,c ;

a=10;

b=20;

C= a+b

Cout<<c;

getch ();

}

Page 2: C++ assignment

Program No:2 (Subtraction of Two no’s)# include <iostream.h>

# include <conio.h>

Void main (void)

{

Int a,b,c ;

Clrscr();

Cout<< “subtraction of two values “ <<endl<<endl;

Cout<<”enter the value for a” <<endl;

Cin>>a;

Cout<<”enter the value for b”<<endl;

Cin>>b;

C=a-b;

Cout<<endl<<endl<<”subtraction”<<c ;

getch();

}

Page 3: C++ assignment

Program No: 3 (Cube)# include <iostream.h>

# include<conio.h>

Void main (void)

{

Int r, cube ;

Clrscr () ;

Cout<<”enter the value for integer”<<endl ;

Cin>>r;

Cube = r*r*r ;

Cout<<endl<<endl<<”cube”<<cube;

getch () ;

}

Page 4: C++ assignment

Progam No:4 (Area of Circle)# include <iostream.h>

# include <conio.h>

Void main (void)

{

Float pi ,r ,area ;

Clrscr ();

Cout<<”enter the value for radius”<<endl ;

Cin>>r;

Area = Pi*(r*r) ;

cout<<end<<endl<<”area”<<area ;

getch () ;

}

Page 5: C++ assignment

Program No:5 (circumference of circle)# include <iostream.h>

# include <conio.h>

Void main (void)

{

Float pi,r, circumference ;

Clrscr () ;

Pi = 3.14;

Cout<<”enter the value of radius”<<endl ;

Cin>>r ;

Circumference = 2*(pi)*(r);

Cout<<endl<<endl<<”circumference= ”<<circum…;

getch () ;

}

Page 6: C++ assignment

Program No:6 (Area of Triangle)# include <iostream.h>

# include <conio.h>

Void main (void)

{

Float base, height ,triangle ;

Clrscr () ;

Count<< ”enter the value of base”<<endl;

Cin>>base;

Cout<< “enter the value of the height “<<endl;

Cin>>height;

Triangle = 0.5*(base*height);

Cout<<endl<<endl<<”triangle= ”<<triangle;

getch () ;

}

Page 7: C++ assignment

Program No:7 (Constant Number)#include <iostream.h>

# include <conio.h>

Void main (void)

{

Clrscr () ;

Const int a= 20 ;

Int b=10, c ;

b=b+1;

c=a+b;

cout<<c;

getch () ;

}

Page 8: C++ assignment

Program No: 8 (For Loop)# include <iostream.h>

# include <conio.h>

Void main (void)

{

Clrscr () ;

Int a ;

Cout <<”Enter any number, and will generate its table”<<endl;

Cin>>a;

Cout <<”upto which extent table must be generated “<<endl;

Cin>> = z;

Cout <<endl;

for ( int i=1 ; i<=z ; i++ )

cout <<a<< ”*” <<i<< ”=” << a*1 <<endl;

getch () ;

}

Page 9: C++ assignment

Program No: 9 ( Average )# include<constream.h>

Void main (void)

Clrscr () ;

Const int n=5;

Int sum=o;

Int x[ n];

Cout<<”marks of five subjects ”;

Cout<<endl;

for (int i=o; i<n; i++)

{

Cin>>x[i];

}

Int average=sum/n;

Cout<<endl<<”average 15 ”;

Cout<<average;

getch();

}

Page 10: C++ assignment

Program No: 10 ( Factorial )# include<constream.h>

Void main (void)

{

Clrscr () ;

int num , fact=1;

Cout<<”enter the number to calculate its factorial:”;

Cin>>num;

for (int i=1 ; i<=num ; i++)

fact += i ;

Cout<<num<<”!=”<<fact;

getch () ;

}

Page 11: C++ assignment

Program No: 11 ( Array )# include <iostream.h>

# include <conio.h>

Void main (void)

{

Clrscr () ;

Int x[10];

X[0]=2;

X[1]=3;

X[2]=4;

Cout<<x[0];

getch () ;

}

Page 12: C++ assignment

Program No: 12 (Introducton To While Loop)# iunclude <iostream.h>

# include <conio.h>

Void main (void)

{

Clrscr () ;

int a ;

a=1;

While(a<10)

{

Cout<<a<<endl;

a++;

}

getch () ;

}

getch();

}

Page 13: C++ assignment

Program No: 13 (Making a sequence Using while loop)# include <iostream.h>

# include <conio.h>

Void main (void)

Clrscr () ;

Long limit,next,last;

Limit = 1000;

Next=0;

Last=1;

While(last<limit)

{

Cout<<last<<” “endl;

Long sum = next+last;

Next = last;

Last = sum;

}

getch () ;

}

Page 14: C++ assignment

Program No: 14 ( Temperature conversion )# include <iostream.h>

# include <conio.h>

Void main (void)

{

Clrscr();

Int choice;

Float ctemp,ftemp;

Cout<<”1.celsius to Fahrenheit”<<endl;

Cout<<”2.fahrenheit to Celsius”<<endl;

Cout<<”choose between 1&2:”<<endl;

Cin>>choice;

If(choice==1)

{

Cout<<”Enter the temperatre in celsius:”<<endl;

Cin>>ctemp;

Ftemp=(1.8*ctemp)+32;

Cout<< “temperatre in Fahrenheit=”<<ftemp<<endl;

}

Else

{

Cout<<”Enter the temperatre in Fahrenheit : ”<<endl;

Cin>>ftemp;

C temp=(ftemp-32)*0.55;

Cout<<”temperature in celscius= “<<ctemp<<endl;

}

getch () ;

}

Page 15: C++ assignment

Program No: 15 ( Pre Increment )# include <iostrem.h>

# include <conio.h>

Void main (void)

{

Clrscr () ;

Int a;

a=10;

a=a++;

cout<<a;

getch () ;

}

Page 16: C++ assignment

Program No : 16 ( Display cube series 1 to 10 )# include < constream.h >

# include < iomanip.h >

Void main () ;

int a ;

for ( a=1 ; a<=10 ; a=a+1 )

{

Cout << set w (50)<<a;

int cube = a*a*a;

cout<<setw(6)<<cube<<endl; }

getch () ; }

Page 17: C++ assignment

Program No: 17 ( For Pattern )# include <iostream.h>

# include <conio.h>

Void main (void)

{

Clrscr () ;

for (int i = I ; i<=5 ; i++)

{

for (int j=1 ; j<=I ; j++)

{

Cout<< ”*” ;

}

Cout<<endl ;

}

getch () ;

}

Page 18: C++ assignment

Program No: 18 ( for loop repetition of Name)# include <iostream.h>

# include <conio.h>

Void main (void)

{

Clrscr () ;

Int a;

a=1;

For (a=1 ; a<=10 ; a++)

Cout<<”zohaib”<<endl;

getch () ;

}

Page 19: C++ assignment

Program No: 19 ( Table of Two by for loop )

# include <iostream.h>

# include <conio.h>

Void main (void)

{

Clrscr () ;

Int a;

a=1;

for (a=1 ; a<=10 ; a++)

cout<<2<< ”*” <<a<< ”=” << a*2 <<endl;

getch () ;

}

Page 20: C++ assignment

Program No : 20 ( Logical )# include <iostream.h>

# include <conio.h>

Void main (void)

{

Clrscr () ;

Int a = 10 , b = 25;

Cout <<”a>b is ”<< (a>b )<<endl;

Cout <<”a<b is “<<(a<b)<<endl;

Cout <<”a==b is ”<<(a==b)<<endl;

Cout <<”a>=b is ”<<(a>=b)<<endl;

Cout <<”a<=b is ”<<(a<=b)<<endl;

Cout <<”a!=b is ”<<(a!=b)<<endl;

getch () ;

}

Page 21: C++ assignment

Program No: 21 ( Post Increment)# include <iostream.h>

# include <conio.h>

Void main (void)

{

Clrscr () ;

Int a;

a = 12;

cout <<a++<<endl;

cout <<++a;

getch () ;

}

Page 22: C++ assignment

Program No: 22 ( Do While )# include <iostream.h>

# include <conio.h>

Void main ( void )

{

float dividend,divisor;

char ch;

do

{

Cout<<”Enter Dividend”<<endl;

Cin>>dividend;

Cout<<”Enter divisor”<<endl;

Cin>>divisor;

Cout<<”QUOTIENT IS = “<<dividend/divisor<<endl;

Cout<<”DO YOU WANT TO PERFORM ANOTHER (Y/N)?”;

Cin>>ch;

}

While (ch!=’n’);

getch () ;

}

Page 23: C++ assignment

Program No:23 (Conditional Operator )# include <iostream.h>

# include <conio.h>

Void main (void)

{

int a,b,c;

clrscr () ;

cout<<”Enter value of a:” ;

cin >> a;

cout<<”Enter the value of b:”;

cin>>b;

c= a>b?a:b;

cout<<a<<”is greatest”;

getch ();

}

Page 24: C++ assignment

Program No: 24 ( Power Dissipation )# include <iostream.h>

# include <conio.h>

Void main (void)

{ clrscr ();

Float V,I,R,P;

Cout<<”Enter the voltage across the resistor :”<<endl;

Cin>>V;

Cout<<”Enter the current through resistor :”<<endl;

Cin>>I;

R=V/I;

P=(I*I)*R;

Cout<<”The power dissipation is :”<<P<<”watts”<<endl;

If (P>100)

Cout<<”Alert! There is too much dissipation”;

getch();

}

Page 25: C++ assignment

Program No: 25 ( Addition of square,cube,fourth )# include <iostream.h>

# include <conio.h>

int square;

int cube;

int fourth;

void main (void)

{

Clrscr();

int x,y,z,X1,Y1,Z1,fX;

cout<<”Enter the value of X”;

cin>>x;

cout<<”Enter the value of Y”;

cin>>y;

cout<<endl<<”Enter the value of Z”;

cin>>z;

X1= square;

Y1=cube;

Z1=fourth;

Cout<<”Result of f(x) is”<<fx;

getch();

}

Page 26: C++ assignment

Program No: 26 (Parametric Area)# include <iostream.h>

# include <conio.h>

Void main (void)

{

Clrscr();

int L;

int W;

int A;

int P;

float T;

cout<<”length=”;

cin>>L;

cout<<”width=”;

cin>>w;

A=l*W;

Cout<<”Area=”<<A;

P=(2*l)+(2*W);

Cout<<”/n param=”<<P;

T=0.5*(L*W)’

Cout<<”/n Area Tri=”<<T;

getch();

}

Page 27: C++ assignment