Problem 1
#include <iostream>
using namespace std;
class student {
public:
string name;
int roll_no;
};
int main() {
student st1;
[Link] = "john";
st1.roll_no = 2;
cout << "Name: " << [Link] << endl;
cout << "roll: " << st1.roll_no << endl;
return 0;
Problem 2
#include <iostream>
using namespace std;
class Student{
public:
string roll_no,phonenumber;
string name,address;
void printDetails(){
cout<<"Name: "<<name<<endl;
cout<<"Address: "<<address<<endl;
cout<<"Roll no: "<<roll_no<<endl;
cout<<"Phone number: "<<phonenumber<<endl;
};
int main(){
Student student1,student2;
[Link] = "Sam";
[Link] = "kuril";
student1.roll_no = "19";
[Link] = "0123456789";
[Link]();
cout<<endl;
[Link] = "John";
[Link] = "Nikunjo";
student2.roll_no = "11";
[Link] = "0123456789";
[Link]();
return 0;
}
Problem 3
#include <iostream>
#include<cmath>
using namespace std;
class Triangle {
public:
double side1, side2, side3;
double area(){
double s = (side1 + side2 + side3) / 2.0;
double area = sqrt(s*(s - side1)*(s - side2)*(s - side3));
return area;
double perimeter() {
return side1 + side2 + side3;
void display(){
cout << "Area: " << area()<<endl;
cout << "Perimeter: "<< perimeter()<<endl;
};
int main() {
Triangle triangle;
triangle.side1 = 3;
triangle.side2 = 4;
triangle.side3 = 5;
[Link]();
return 0;
Problem 4
#include <iostream>
using namespace std;
class Triangle
public:
int s1, s2, s3;
Triangle(int a, int b, int c)
s1 = a;
s2 = b;
s3 = c;
void print_area()
double s = (s1+s2+s3)/2;
cout << "Area: "<<s<< endl;
cout << "Perimeter is " << (s1+s2+s3) << endl;
};
int main()
Triangle t(3,4,5);
t.print_area();
return 0;
}
Problem 5
#include <iostream>
using namespace std;
class Rectangle {
public:
int length;
int breadth;
Rectangle(int l, int b) {
length = l;
breadth = b;
int Area() {
return length * breadth;
};
int main() {
Rectangle r1(4, 5);
Rectangle r2(5, 8);
cout << "Area of Rectangle 1: " << [Link]() << endl;
cout << "Area of Rectangle 2: " << [Link]() << endl;
return 0;
Problem 6
#include <iostream>
using namespace std;
class Area{
public:
int length;
int breadth;
void setDim(int l, int b) {
length = l;
breadth = b;
int getArea(){
return length*breadth;
};
int main(){
Area a;
[Link](4,5);
cout << [Link]() << endl;
return 0;
Problem 7
#include <iostream>
using namespace std;
class Area {
public:
int length;
int breadth;
Area(int l, int b) {
length = l;
breadth = b;
int returnArea() {
return length * breadth;
};
int main() {
int l, b;
cout << "Enter length of rectangle: ";
cin >> l;
cout << "Enter breadth of rectangle: ";
cin >> b;
Area a(l, b);
cout << "Area of rectangle: " << [Link]();
return 0;
Problem 8
#include <iostream>
using namespace std;
class Average {
public:
void calculateAverage(int num1, int num2, int num3){
double average = (double)(num1 + num2 + num3) / 3.0;
cout << "The average of the three numbers is: " << average << std::endl;
};
int main()
int num1, num2, num3;
cout << "Enter the first number: ";
cin >> num1;
cout << "Enter the second number: ";
cin >> num2;
cout << "Enter the third number: ";
cin >> num3;
Average().calculateAverage(num1, num2, num3);
return 0;
}
Problem 9
#include <iostream>
using namespace std;
class Complex {
public:
float real;
float imag;
Complex(float r = 0, float i = 0) {
real = r;
imag = i;
Complex operator + (Complex const &obj) {
Complex res;
[Link] = real + [Link];
[Link] = imag + [Link];
return res;
Complex operator - (Complex const &obj) {
Complex res;
[Link] = real - [Link];
[Link] = imag - [Link];
return res;
Complex operator * (Complex const &obj) {
Complex res;
[Link] = real * [Link] - imag * [Link];
[Link] = real * [Link] + imag * [Link];
return res;
}
};
int main() {
Complex c1, c2;
cout << "Enter real and imaginary parts of first complex number: ";
cin >> [Link] >> [Link];
cout << "Enter real and imaginary parts of second complex number: ";
cin >> [Link] >> [Link];
Complex sum = c1 + c2;
Complex diff = c1 - c2;
Complex prod = c1 * c2;
cout << "Sum = " << [Link] << " + " << [Link] << "i" << endl;
cout << "Difference = " << [Link] << " + " << [Link] << "i" << endl;
cout << "Product = " << [Link] << " + " << [Link] << "i" << endl;
return 0;
Problem 10
#include <iostream>
using namespace std;
class Volume{
private:
int length;
int width;
int height;
public:
void set(int l, int w, int h){
length=l;
width=w;
height= h;
int getvol(){
return length*width*height;
};
int main(){
Volume rect;
int length , width,height;
cout<<"Enter the length:";
cin>>length;
cout<<"Enter the width: ";
cin>>width;
cout<<"Enter the height: ";
cin>>height;
[Link](length, width, height);
int volume = [Link]();
cout<<"The Volume is: "<<volume;
return 0;