Вы находитесь на странице: 1из 70

DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-1

TITLE :- Write a program to print a simple comment.

CODE:-

#include<iostream.h>

#include<conio.h>

void main()

cout<<”\n WELCOME TO SSU”;

cout<<”\n \n My Name is MANISHA”;

getch();

1
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

EXPERIMENT:-2

TITLE :- Write a program to perform all mathematical functions by using


different numbers.

2
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

CODE:-

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a,b,add,sub,multiply,divide,modulus;

cout<<”\n enter the value of a:”;

cin>>a;

cout<<”\n enter the value of b:”;

cin>>b;

add=a+b;

cout<<”\n The result of addition is=”<<add;

cout<<”\n enter the value of a:”;

cin>>a;

cout<<”\n enter the value of b:”;

cin>>b;

sub=a-b;

cout<<”\n The result of subtraction is=”<<sub;

cout<<”\n enter the value of a:”;

cin>>a;

3
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

cout<<”\n enter the value of b:”;

cin>>b;

multiply=a*b;

cout<<”\n The result of multiplication is=”<<multiply;

cout<<”\n enter the value of a:”;

cin>>a;

cout<<”\n enter the value of b:”;

cin>>b;

divide=a/b;

cout<<”\n The result of division is=”<<divide;

cout<<”\n enter the value of a:”;

cin>>a;

cout<<”\n enter the value of b:”;

cin>>b;

modulus=a%b;

cout<<”\n The result of modulus is=”<<modulus;

getch();

4
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

EXPERIMENT:-3

TITLE :- Write a program to print the numbers entered by the user.

5
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

CODE:-

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a,b,c;

cout<<”\n enter the value of a:”;

cin>>a;

cout<<”\n enter the value of b:”;

cin>>b;

cout<<”\n enter the value of c:”;

cin>>c;

cout<<”\n The first value entered by the user is =”<<a;

cout<<”\n The second value entered by the user is=”<<b;

cout<<”\n The third value entered by the user is =”<<c;

getch();

6
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

EXPERIMENT:-4

TITLE :- Write a program to find whether a number is even or odd.

CODE:-

#include<iostream.h>

7
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

#include<conio.h>

void main()

clrscr();

int a;

cout<<”\n enter the value of a:”;

cin>>a;

if(a%2==0)

cout<<”\n The value is even”;

else

cout<<”\n The value is odd”;

getch();

OUTPUT:-

8
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-5

TITLE :- Write a program to find whether a number is Positive, Negative or


Zero.

9
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

CODE:-

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a;

cout<<”\n enter the value of a:”;

cin>>a;

if(a>0)

cout<<”\n The value is positive”;

else if(a<0)

cout<<”\n The value is negative”;

else

cout<<”\n The value is zero;

getch();

OUTPUT:-

10
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-6

TITLE :- Write a program to find the largest of three numbers.

CODE:-

#include<iostream.h>

#include<conio.h>

void main()

11
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

clrscr();

int a,b,c;

cout<<”\n enter the value of a:”;

cin>>a;

cout<<”\n enter the value of b:”;

cin>>b;

cout<<”\n enter the value of c:”;

cin>>c;

if(a>b&&a>c)

cout<<”\n a is greater”;

else if(b>a&&b>c)

cout<<”\n b is greater”;

else

cout<<”\n c is greater”;

getch();

12
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

13
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-7

TITLE :- Write a program to convert Celsius into Fahrenheit.

CODE:-

#include<iostream.h>

#include<conio.h>

14
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

void main()

clrscr();

int cel, frh;

cout<<”\n enter the value of cel:”;

cin>>cel;

frh=(1.8*cel)+32;

cout<<”\n The value of frh is =”<<frh;

getch();

OUTPUT:-

15
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-8

TITLE :- Write a program to find whether the student is eligible for exams
according to their attendance and marks .

CODE:-
16
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

#include<iostream.h>

#include<conio.h>

void main()

clrscr();
int marks,atten;

cout<<”\n enter the marks of student: ”;

cin>>marks;

cout<<”\n enter the attendance of student: ”;

cin>>atten;

if(marks>40||atten>75)

cout<<”\n student is eligible”;

else

cout<<”\n student is not eligible”;

getch();

OUTPUT:-

17
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-9

TITLE :- Write a program to implement scope resolution operator.

CODE:-

#include<iostream.h>

18
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

#include<conio.h>

int a=20;

void main()

clrscr();

int a=60;

int b=a;

int a=30;

cout<<”\n currently we are in inner block”;

cout<<”\n the value of variable b is=”<<b;

cout<<”\n the value of variable a is=”<<a;

cout<<”\n the value of a using scope resolution operator is=”<::a;

cout<<”\n currently we are in outer block”;

cout<<”\n the value of variable a is=”<<a;

cout<<”\n the value of a using scope resolution operator is=”<::a;

getch():

19
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

20
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-10

TITLE :- Write a program to implement the type cast operator.

CODE:-

#include<iostream.h>

#include<conio.h>

21
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

void main()

clrscr();

int a,b,c,d,e,t,sum,count;

float average;

cout<<”\n enter the value of a:”;

cin>>a;

cout<<”\n enter the value of b:”;

cin>>b;

cout<<”\n enter the value of c:”;

cin>>c;

cout<<”\n enter the value of d:”;

cin>>d;

cout<<”\n enter the value of e:”;

cin>>e;

cout<<”\n enter the count by user:”;

cin>>count;

sum=a+b+c+d+e;

cout<<”\n sum of five numbers is=”<<sum;

average=sum/count;

cout<<”\n type conversion value of average is=”<<average;

22
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

average=(float)sum/count;

cout<<\n after type conversion of average=”<<average;

getch();

OUTPUT:-

23
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-11

TITLE:-Write a program to implement the manipulators.

CODE:-

#include<iostream.h>
#include<conio.h>

24
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

#include<iomanip.h>
void main()
{
clrscr();
int i, time;
float p,r,interest;
for(i=1;i<=3;i++)
{
cout<<"\n enter the value of p = ";
cin>>p;
cout<<"\n enter the value of r = ";
cin>>r;
cout<<"\n enter the value of time = ";
cin>>time;
interest=(p*r*time)/100;
cout<<"\n value of interest:";
cout<<setw(26)<<interest;
getch();
}
}

OUTPUT:-

25
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-12

26
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

TITLE:-Write a program using switch statement in which the initial amount


for bank transfer is to be given by input by user and three cases are to be
form

1. Credit
2. Debit
3. Balance enquiry

The program will ask the user to select appropriate case and print the new
amount as output.

CODE:-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,amount,choice;
cout<<"\n enter initial amount: ";
cin>>a;
cout<<"\n 1:credit";
cout<<"\n 2:debit";
cout<<"\n 3:balance enquiry:";
cout<<"\n please enter your choice: ";
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"\n please enter amount to be credit= ";
cin>>b;

27
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

amount=a+b;
cout<<" \n amount after credit : "<<amount;
break;
}
case 2:
{
cout<<"\n enter the amount of debit= ";
cin>>b;
if(a>b)
{
amount=a-b;
cout<<"\n amount after debit : "<<amount; }
else
{
cout<<"\n you dont have enough amount";
}
break;
}
case 3:
{
amount=a;
cout<<"\n your current amount is = "<<amount;
break;
}
default:
{
cout<<"\n please enter the correct choice";
break;
}}
getch();
}

28
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

29
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

30
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-13

TITLE:-Write a program to implement the concept of prototyping

CODE:

#include<iostream.h>
#include<conio.h>
float add(float, float);
float sub(float, float);
float multiply(float, float);
float divide(float, float);
void main()
{
clrscr();
float a,b;
cout<<"\n enter any two numbers : ";
cin>>a>>b;
cout<<"\n sumation "<<add(a,b);
cout<<"\n subtraction "<<sub(a,b);
cout<<"\n multiplication "<<multiply(a,b);
cout<<"\n division "<<divide(a,b);
getch();
}
float add(float x, float y)
{
float res;
res=x+y;
return res;
}
float sub(float x, float y)
{

31
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

float res;
res=x-y;
return res;
}
float multiply(float x,float y)
{
float res;
res=x*y;
return res;
}
float divide(float x, float y)
{
if(y==0)
{
cout<<"\n divide by zero error...!!!";
cout<<"\n press any key to exit...!!!";
getch();
}
else
{
float res;
res=x/y;
return res;
}
}

32
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

33
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-14

TITLE:-Write a program to implement the Inline function.

CODE:-

#include<iostream.h>
#include<conio.h>
class operation
{
int a,b,add,sub;
public:
void get();
void sum();
void difference();
};
inline void operation::get()
{
cout<<"\n enter first value= ";
cin>>a;
cout<<"\n enter second value= ";
cin>>b;
}
inline void operation::sum()
{
add=a+b;
cout<<"\n additon of two numbers: "<<add;
}
inline void operation::difference()
{
sub=a-b;
cout<<"\n\n difference of two numbers: "<<sub;

34
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

}
void main()
{
clrscr();
cout<<"\n program using inline function";
operation s;
s.get();
s.sum();
s.difference();
getch();
}

35
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

36
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-15

TITLE:-Write a program to implement the friend function.

CODE:-

#include<iostream.h>
#include<conio.h>
class sahil
{
int a;
int b;
public:
void setvalue()
{
a=4;
b=7;
}
friend float mean(sahil s);
};
float mean(sahil s)
{
return float(s.a+s.b)/2.0;
}
void main()
{
clrscr();
sahil x;
x.setvalue();
cout<<"\n the final value is "<<mean(x);
getch();
}

37
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

38
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-16

TITLE:-Write a program to implement the friend function between two


classes.

CODE:-

#include <iostream.h>
#include<conio.h>
class abc;
class xyz
{
int x;
public:
void setvalue (int i)
{
x=i;
}
friend void max (xyz , abc );
};
class abc
{
int a;
public:
void setvalue (int i)
{
a= i;
}
friend void max(xyz,abc);
};
void max(xyz m , abc n)
{

39
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

if(m.x>=n.a)
{
cout<<m.x;
}
else
{
cout<<n.a;
}}
void main ()
{
abc d;
d.setvalue(10);
xyz e;
e.setvalue(16);
max(e,d);
getch();
}

40
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

41
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-17

TITLE:-Write a program to implement the friend function.

CODE:-

#include<iostream.h>
#include<conio.h>
class number
{
private:
int a;
public:
void getnum(int x);
friend void printnum(number num)
};
void number::getnum(int x)
{
a=x;
}
void printnum(number num)
{
cout<<"\n value of a(private data member of class memeber):"<<num.a;
}
void main()
{
clrscr();
number nobj;
nobj.getnum(2000);
printnum(nobj);
getch();
}

42
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

43
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-18

TITLE:-Write a program to implement the friend function.

CODE:-

#include<iostream.h>
#include<conio.h>
class Box
{
double width;
public:
friend void printwidth(Box box);
void setwidth( double wid );
};
void Box ::setwidth(double wid)
{
width = wid;
}
void printwidth ( Box box )
{
cout<<"\n Width of box : "<<box.width <<endl;
}
void main()
{
clrscr();
Box box ;

44
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

box.setwidth(10.9);
printwidth(box);
getch();
}

OUTPUT:-

45
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-19

TITLE:-Write a program to implement the friend function.

CODE:-

#include<iostream.h>

#include<conio.h>
class example
{
private:
int a;
public:
void getdata()
{
cout<<"\n enter value of a:";
cin>>a;
friend void findmax(example , example);
};
void findmax(example e1,example e2)
{
if(e1.a>e2.a)
cout<<"\n data of object e1 is greater ";
else if(e1.a<e2.a)

46
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

cout<<"\n data of object e2 is greater ";


else
cout<<"\n data of object e1 and e2 are equal";
}
void main()
{
clrscr();
example e1,e2;
cout<<"\n enter data for e1";
e1.getdata();
cout<<"\n enter data for e2";
e2.getdata();
findmax(e1,e2);
getch();
}

47
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

48
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-20

TITLE:-Write a program to find the factorial of a number entered by user


using the concept of recursion.

CODE:-

#include<iostream.h>
#include<conio.h>
int factorial(int n);
void main()
{
clrscr();
int n;
cout<<"\n enter a positive integer:";
cin>>n;
cout<<"\n factorial of "<<n<<"="<<factorial(n);
getch();
}
int factorial(int n)
{
if(n>1)
return n*factorial(n-1);
else

49
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

return 1;
}

OUTPUT:-

50
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-21

TITLE:-Write a program to find the factorial of a number.

CODE:-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,fact=1,number;
cout<<"\n enter any number:";
cin>>number;
for(i=1;i<=number;i++)
{
fact=fact*i;
}
cout<<"\n factorial of "<<number<<" is "<<fact;
getch();
}

51
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

52
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-22

TITLE:-Write a program to implement the concept of array of objects.

CODE:-

#include<iostream.h>
#include<conio.h>
class employee
{
char name[30];
float age;
public:
void getdata(void);
void putdata(void);
};
void employee::getdata(void)
{

53
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

cout<<"\n enter the name of employee = ";


cin>>name;
cout<<"\n enter the age of employee = ";
cin>>age;
}
void employee::putdata(void)
{
cout<<"\n name of eployee: "<<name;
cout<<"\n age of employee: "<<age;
}
const int size=2;
void main()
{
clrscr();
employee manager[size];
for(int i=0;i<size;i++)
{
cout<<"\n details of manager "<<i+1;
manager[i].getdata();
}
for(i=0;i<size;i++)
{
cout<<"\n manager "<<i+1;
manager[i].putdata();
}
getch();
}

54
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

55
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-23

TITLE:-Write a program to implement the static member function .

CODE:-

#include<iostream.h>
#include<conio.h>
class test
{
int code;
static count;
public:
void setcode(void)
{
code=++count;
}
void showcode(void)
{

56
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

cout<<"\n the current number of object is "<<code;


}
static void showcount(void)
{
cout<<"\n the value of count variable "<<count;
}};
int test::count;
void main()
{
clrscr();
test t1,t2;
t1.setcode();
t2.setcode();
test::showcount();
test t3;
t3.setcode();
test::showcount();
t1.showcode();
t2.showcode();
t3.showcode();
getch();
}

57
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

58
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-24

TITLE:-Write a program to implement the static data member .

CODE:-

#include<iostream.h>
#include<conio.h>
class item
{
static int count;
int number;
public:
void getdata(int a)
{
number=a;
count++;
}
void getcount(void)
{

59
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

cout<<"\n value of counter is "<<count;


}
};
int item::count;
void main()
{
clrscr();
item a,b,c;
a.getcount();
b.getcount();
c.getcount();
a.getdata(100);
b.getdata(200);
c.getdata(300);
cout<<"\n after reading the whole data the final value of count wil be ";
a.getcount();
b.getcount();
c.getcount();
getch();
}

60
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

61
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-25

TITLE:- Write a program to implement the nesting of members.

CODE:_

#include<iostream.h>
#include<conio.h>
class set
{
int m,n;
public:
void input(void);
void display(void);
int largest(void);
};
int set::largest(void)
{
if(m>=n)
return(m);
else

62
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

return(n);
}
void set::input(void)
{
cout<<"\n input value of m and n ";
cin>>m>>n;
}
void set::display (void)
{
cout<<"\n largest value= ";
cout <<largest()<<"\n";
}
void main()
{
clrscr();
set a;
a.input();
a.display();
getch();
}

63
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

64
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-26

TITLE:- Write a program of constructors in c++.

CODE:

#include<iostream.h>
#include<conio.h>
class integer
{
int m,n;
public:
integer(int, int);
void display(void)
{
cout<<"\n m = "<<m;
cout<<"\n n = "<<n;
}
};
integer::integer(int x, int y)
{

65
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

m=x;
n=y;
}
void main()
{
clrscr();
integer int1(0,900);
integer int2=integer(45,75);
cout<<"\n object1 ";
int1.display();
cout<<"\n object2 ";
int2.display();
getch();
}

66
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

67
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

EXPERIMENT:-27

TITLE:- Write a program for constructor overloading with the help of class.

CODE:_
#include<iostream.h>
#include<conio.h>
class complex
{
float x,y;
public:
complex(){}
complex (float a)
{
x=y=a;
}
complex( float real, float imag)
{
x=real;
y=imag;
}
friend complex sum(complex, complex);

68
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

friend void show(complex);


};
complex sum(complex c1, complex c2)
{
complex c3;
c3.x=c1.x+c2.x;
c3.y=c1.y+c2.y;
return(c3);
}
void show (complex c)
{
cout<<c.x<<" +j "<<c.y<<"\n ";
}
void main()
{clrscr();
complex A(4.4, 5.4);
complex B(8.7);
complex C;
C=sum(A,B);
cout<<"\n the value of a";
show(A);
show(B);
show(C);
getch();
}

69
REG.NO. -317021002
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

OUTPUT:-

70
REG.NO. -317021002

Вам также может понравиться