National Institute of Technology, Kurukshetra: Department of Electrical Engineering
National Institute of Technology, Kurukshetra: Department of Electrical Engineering
Programme:-
#include<iostream>
class complex
public:
int a,b;
void get_data()
int x,y;
cin>>x>>y;
a=x;
b=y;
void show_data()
cout<<"\na="<<a<<"\nb="<<b;
complex temp;
temp.a=c1.a+c2.a;
temp.b=c1.b+c2.b;
return(temp);
};
int main()
complex c1,c2,c3;
c1.get_data();
c2.get_data();
c3=add(c1,c2);
c3.show_data();
return 0;
}
RESULT:-
EXPERIMENT:-2
Programme:-
#include<iostream>
class student
public:
string name;
int roll_no;
int marks;
void get_data();
void print_data();
void print_grade();
};
void student::get_data()
cin>>name>>roll_no>>marks;
}
void student::print_data()
cout<<"display";
void student::print_grade()
if(marks>=85)
cout<<"A+";
else if(marks<85&&marks>=75)
cout<<"A";
else if(marks<75&&marks>=65)
cout<<"B";
else if(marks<65&&marks>=50)
cout<<"C";
else if(marks<50&&marks>=40)
cout<<"D";
else
cout<<"fail";
int main()
student s[10];
s[1].get_data();
s[1].print_data();
s[1].print_grade();
return 0;
}
RESULT:-
Problem(b):-Write a program to overload + and * operators to add
and multiply two numbers.
Programe:-
#include<iostream>
class complex
int a;
int b;
public:
a=x;
b=y;
void show()
if (b>=0)
std::cout<<a<<"+j"<<b<<"\n";
if(b<0)
std::cout<<a<<"-j"<<-b<<"\n";
}
};
complex temp;
temp.a = a +c.a;
temp.b = b +c.b;
return temp;
}
complex temp;
temp.a =a*(c.a)-b*(c.b);
temp.b= a*(c.b)+b*(c.a);
return temp;
int main()
complex a,b,c,d;
a.get(4,-4);
b.get(2,3);
c= a+b;
d= a*b;
a.show();
b.show();
c.show();
d.show();
return 0;
}
RESULT:-
EXPERIMENT NO:-3
Programme:-
#include<iostream>
class animal
public:
void show_data()
};
public:
void show_data1()
};
public:
void show_data2()
};
public:
void show_data3()
};
int main()
animal a1;
dog d1;
cat c1;
puppy p1;
a1.show_data();
d1.show_data1();
c1.show_data2();
p1.show_data3();
return 0;
RESULT:-
EXPERIMENT NO:-4
class Student
public:
int Roll_no;
string name;
void get_input()
cin>>Roll_no;
cin>>name;
cin>>phone_no;
void info()
cout<<"Roll no:-"<<Roll_no<<endl;
cout<<"name:-"<<name<<endl;
cout<<"phone no:-"<<phone_no<<endl;
};
int main()
Student s1 ,*p_st;
s1.get_input();
p_st=&s1;
p_st->info();
return 0;
}
RESULT:-
EXPERIMENT:-5
Programme:-
#include<iostream>
class animal
public:
void show_data()
};
public:
void show_data1()
show_data();
}
};
public:
void show_data2()
};
public:
void show_data3()
};
int main()
puppy p;
cat c;
p.show_data3();
p.show_data1();
c.show_data2();
return 0;
}
RESULT:-
EXPERIMENT:- 6
Programme:-
#include<iostream>
class Base
public:
};
public:
};
int main(void)
{
Base *bp = new Derived;
return 0;
}
Result:-
EXPERIMENT:-7
Programme:-
#include<iostream>
class bill
public:
int units,ammount,base=200;
void get_data()
cin>>units;
void show_data()
cout<<"units: "<<units<<endl;
void total_bill()
{
if(units<=base)
ammount=units*6;
else if(units>=base)
ammount=(base*6)+(units-200)*10;
else
cout<<"error"<<endl;
};
};
int main()
bill b;
b.get_data();
b.show_data();
b.total_bill();
return 0;
}
RESULT:-
EXPERIMENT:-8
Programme:-
#include<iostream>
class game_of_chance
public:
int a,b,no_of_chance=200;
void get_data()
cin>>no_of_chance;
cin>>a;
cin>>b;
}
void game_result()
if((a+b)!=no_of_chance)
cout<<"invalid"<<endl;
else if(a>b)
cout<<"nikhil wins"<<endl;
else
cout<<"vani wins"<<endl;
};
int main()
game_of_chance g;
g.get_data();
g.game_result();
return 0;
}
RESULT:-
EXPERIMENT:-9
Programme:-
#include<iostream>
#include<cmath>
template<class T>
T D=b*b-4*a*c;
if(D==0)
cout<<" x ="<<-b/2*a<<endl;
else if(D>0)
float r=sqrt(D);
else
float r=sqrt(-D);
cout<<" x1 = "<<-b/2*a<<" +i"<<r/2*a<<" x2 = "<<-b/2*a<<" -
i"<<r/2*a<<endl;
};
int main()
root(2,3,4);
return 0;
}
RESULT:-