Assignment 1 OOP 1
Assignment 1 OOP 1
Course Code:
CC 1022L
#include <iostream>
using namespace std;
class Rectangle
{
private:
double length;
double width;
public:
void setlength(double l)
{
length = l;
}
double getlength()
{
return length;
}
void setwidth(double w)
{
width = w;
}
double getwidth()
{
return width;
}
double area()
{
double perimeter = 2 * length + 2 * width;
return perimeter;
}
int perimeter()
{
int area = length * width;
return area;
}
};
int main()
{
Rectangle r1;
r1 . setlength(6.25);
r1 . setwidth(8.2);
cout << "The Area of the Rectangle is: " << r1.area() << endl;
cout << "The Perimeter of the Rectangle is: " << r1.perimeter() << endl;
return 0;
}
Output:
TASK 2:
#include <iostream>
using namespace std;
class color
{
public:
int r;
int g;
int b;
string CLR;
color(int R=0, int G=0, int B=0, string clr="White")
{
r = R;
g = G;
b = B;
CLR = clr;
}
void display()
{
cout << r << " " << g << " " << b << " " << CLR << endl;
}
};
int main()
{
color c1(1, 2, 3, "Black");
color c2;
c1.display();
c2.display();
return 0;
}
Output:
TASK 3:
#include <iostream>
using namespace std;
class Student
{
public:
int english;
int oop;
int discrete_structures;
int calculus;
int islamiyat;
Student (int eng = 78, int op = 86, int disc = 100, int cal = 98, int islam = 50)
{
english = eng;
oop = op;
discrete_structures = disc;
calculus = cal;
islamiyat = islam;
}
void display ()
{
cout << "The number of Subject English are: " << english << endl;
cout << "The number of Subject Object-Oriented Programming are: " << oop << endl;
cout << "The number of Subject Discrete Structures are: " << discrete_structures << endl;
cout << "The number of Subject Calculus are: " << calculus << endl;
cout << "The number of Subject Islamiyat are: " << islamiyat << endl << endl;
}
};
int main()
{
Student s1(51, 52, 53, 54, 54);
s1.display();
Student s2;
s2.display();
Student s3(70, 65, 92, 49, 38);
s3.display();
return 0;
}
Output:
TASK 4:
#include <iostream>
using namespace std;
class Circle
{
public:
double radius;
Circle (double r)
{
radius = r;
}
double getarea ()
{
double area1 = 3.14 * (radius * radius);
return area1;
}
double getperimeter ()
{
double perimeter = 2 * (3.14 * radius);
return perimeter;
}
};
int main()
{
Circle c1(4);
cout << "The area of Circle is: " << c1.getarea() << endl;
cout << "The perimeter of the Circle is: " << c1.getperimeter() << endl << endl;
Circle c2(9);
cout << "The area of Circle is: " << c2.getarea() << endl;
cout << "The perimeter of the Circle is: " << c2.getperimeter();
return 0;
}
Output: