شيئية OOP
282 subscribers
53 photos
10 files
12 links
عمي رحمة لوالديك ولعشيرتك وللعزاز وللعراق وللشرق الأوسط، لا تكعد تحفظ الأكواد
الكود فهم فهم فهم مو حفظ
و السلام
Download Telegram
بالنسبة ل7و8و9
نفسهم 4و5و6
Ex10 :
Design an application to calculate the area of any rectangle shape. The application should contain a class called Shape with two variables (length, width). Then generate a class with name (Rectangle) that publicly inherits the attributes of the other class, and has a method to calculate the area of any rectangle. Instantiate an object called Rect of type Shape. Use an appropriate setter function to initialize the variable.

#include <iostream>
using namespace std;

class Shape {
protected :
double length;
double width;
public :
void setDim(double l, double w) {
length = l;
width = w;
}
};


class Rectangle : public Shape {
public:

double getArea() {
return ( length * width);
}
};


int main()
{
Rectangle Rect;
Rect.setDim (9.5, 3.6);
cout << Rect.getArea() << endl;
return 0;
}
👍31🎄1
Ex11 :
Design an application to calculate the area of any rectangle shape. The application should contain a class called Shape with two variables (length, width). Then generate a class with name (Rectangle) that privately inherits the attributes of the other class, and has a method to calculate and display the area of any rectangle. Instantiate an object called Rect of type Shape. Use constructor to initialize the variable.

#include <iostream>
using namespace std;

class Shape {
protected :
double length;
double width;

public :
Shape (double l, double w) {
length = l;
width = w;
}
};


class Rectangle : private Shape {
public :
Rectangle (double l, double w) : Shape (l, w) {}

double getArea() {
return length * width;
}

void display() {
cout << getArea() << endl;
}
};


int main()
{
Rectangle Rect = {9.2, 4.7};
Rect.display();
return 0;
}
3🥱2
Ex12 :
Design an application to calculate the area of any rectangle shape. The application should contain a class called Shape with two variables (length, width). Then generate a class with name (Rectangle) that privately inherits the attributes of the other class, and has a method to calculate and display the area of any rectangle. Instantiate an object called Rect of type Shape. Use constructor to initialize the variable.

Note: The variable name in the constructor should be same as the name of member variables.

#include <iostream>
using namespace std;

class Shape {
protected :
double length;
double width;

public :
Shape (double length, double width) {
this->length = length;
this->width = width;
}
};


class Rectangle : private Shape {
public :
Rectangle (double length, double width) : Shape (length, width) {}

double getArea() {
return length * width;
}

void display() {
cout << getArea() << endl;
}
};


int main()
{
Rectangle Rect = {9.2, 4.7};
Rect.display();
return 0;
}
👍21
Ex13 :
Design an application to calculate sum and average for three subjects. This application contains a class called Person with four variables (studentName, OOP, Math, and English) and a method (subjectSum) to calculate the sum of three subject. Define another class called StudentAverage with a method (void Average) to calculate the average of three subject. The third class (Students) should inherit the data members and methods from both classes. Instantiate an object called Student of type Students. Use constructor to initialize the variables.

#include <iostream>
using namespace std;

class person {
protected :

string name;
int oop;
int math;
int english;

public :
person (string n, int o, int m, int e) {
name = n;
oop = o;
math = m;
english = e;
}
int sum() {
return oop + math + english;
}
};


class StudentAverage {
public :
void Average (double gsum) {
cout << gsum/3;
}
};


class students : public person, public StudentAverage {
public :
students (string n, int o, int m, int e) : person(n, o, m, e){}
};


int main()
{
students student = {"mm",98,89,76};
double summ = student.sum();
student.Average(summ);
return 0;
}
👍31
Ex14 :
Design an application to calculate sum and average for three subjects. This application contains a class called Person with four variables (studentName, OOP, Math, and English) and a method (subjectSum) to calculate the sum of three subject. Define another class called StudentAverage with a method (return type Average) to calculate the average of three subject. The third class (Students) should inherit the data members and methods from both classes. Instantiate an object called Student of type Students. Use setter function to initialize the variables.

#include <iostream>
using namespace std;

class person {
protected :

string name;
int oop;
int math;
int english;

public :
int sum() {
return oop + math + english;
}
};


class StudentAverage {
public :
double Average (double gsum) {
return gsum/3;
}
};


class students : public person, public StudentAverage {
public :
void setstudent(string n, int o, int m, int e) {
name = n;
oop = o;
math = m;
english = e;
}
};


int main()
{
students student;
student.setstudent("mogo",98,89,76);
double summ = student.sum();
double avg = student.Average(summ);
cout << avg;
return 0;
}
👍31
Ex15 :
Design an application to calculate sum and average for three subjects. This application contains a class called Person with four variables (studentName, OOP, Math, and English) and a method (subjectSum) to calculate the sum of three subject. Define another class called StudentAverage with a method (void Average) to calculate the average of three subject. The third class (Students) should inherit the data members and methods from both classes. Instantiate an object called Student of type Students. Use setter function to initialize the variables.

#include <iostream>
using namespace std;

class person {
protected :

string name;
int oop;
int math;
int english;

public :
int sum() {
return oop + math + english;
}
};


class StudentAverage {
public :
void Average (double gsum) {
cout << gsum/3;
}
};


class students : public person, public StudentAverage {
public :
void setstudent(string n, int o, int m, int e) {
name = n;
oop = o;
math = m;
english = e;
}
};


int main()
{
students student;
student.setstudent("mogo",98,89,76);
double summ = student.sum();
student.Average(summ);
return 0;
}
👍31
EX16 :
Design a phone call application that has a class called Costumer with three data members (name, phoneNumber, and credit). The application should contain three methods to display the client’s information, top-up (recharge) the credit, and makeCall. The last method should deduct a certain amount from the credit according to the call duration per minute (200 IQD per minute), and issue a message “Insufficient credit to make the call.” in case the credit is less than the cost
per minute

#include <iostream>
using namespace std;

class costumer {
public :
string name;
int phoneNumber;
double credit;

void display () {
cout << "name : " << name << endl;
cout << "phoneNumber : " << phoneNumber << endl;
cout << "credit : " << credit << " IQD " << endl;
}

void topup (double recharge) {
credit += recharge;
}

void makeCall (double amount) {
if (credit >= amount*200) {
credit -= amount*200;
}
else {
cout << "Insufficient credit to make the call" << endl;
}
}
};


int main()
{
costumer person1 = {"mogo", 99880077, 450};
person1.topup(5.500);
person1.makeCall(2);
person1.display();

}
3🥱3
Ex17 :
A phone company asked for an application that has a class called Costumer with three data members (name, phoneNumber, and credit) and two methods one to display the client’s information and the other to top-up (recharge) the credit. The method that allows the clients to make a call (makeCall) is defined in a class called Calling. The implementations of (makeCall) function are deduct a certain amount form the credit according to the call duration (200 IQD per minute) and issue a message “Insufficient credit to make the call.” in case the credit is less than the cost per minute. Define a class called Client that can inherit data members and methods from both classes. Use constructor to initialize the variables.

#include <iostream>
using namespace std;
class Costumer
{
protected:
string name;
int PhoneNumber;
int credit;
public:
Costumer(string name,int PhoneNumber ,int credit){
this->name=name;
this-> PhoneNumber=PhoneNumber;
this->credit=credit;
}
void getCredit(int &a){
a=credit;
}
void top_up(int a){
credit+=a;
}
void display(){
cout<<"name:"<<name<<endl<<"PhoneNumber:"<<PhoneNumber<<endl<<"credit:"<<credit;
}
};
class Calling{
public:
int makeCall(Costumer& c,int s){
int a;
c.getCredit(a);
if(a<=s*200){
cout<<"Insufficient credit to make the call"<<endl;
}else {
c.top_up(-s*200);
return a-=s*200;
}
}
};
class client:public Costumer,public Calling{
public:
client(string name,int PhoneNumber ,int credit):Costumer(name,PhoneNumber,credit){
}
};
int main() {
client c1("yas",3459678,1000);
c1.makeCall(c1,3);
c1.top_up(90);
c1.display();
return 0;
}
2👍2
Ex18 :
A phone company asked for an application that has a class called Costumer with three data members (name, phoneNumber, and credit) and two methods one to display the client’s information and the other to top-up (recharge) the credit. The method that allows the clients to make a call (makeCall) is defined in a class called Calling. The implementations of (makeCall) function are deduct a certain amount form the credit according to the call duration (200 IQD per minute) and issue a message “Insufficient credit to make the call.” in case the credit is less than the cost per minute. Define a class called Client that can inherit data members and methods from
both classes. Use an appropriate setter function to initialize the variables.

#include <iostream>
using namespace std;
class Costumer
{
protected:
string name;
int PhoneNumber;
int credit;
public:
void set(string name,int PhoneNumber ,int credit){
this->name=name;
this-> PhoneNumber=PhoneNumber;
this->credit=credit;
}
void getCredit(int &a){
a=credit;
}
void top_up(int a){
credit+=a;
}
void display(){
cout<<"name:"<<name<<endl<<"PhoneNumber:"<<PhoneNumber<<endl<<"credit:"<<credit;
}
};
class Calling{
public:
int makeCall(Costumer& c,int s){
int a;
c.getCredit(a);
if(a<s*200){
cout<<"Insufficient credit to make the call"<<endl;
}else {
c.top_up(-s*200);
return a;
}
}
};
class client:public Costumer,public Calling{
public:
void set(string name,int PhoneNumber ,int credit){
this->name=name;
this-> PhoneNumber=PhoneNumber;
this->credit=credit;
}
};
int main() {
client c1;
c1.set("yas",3459678,1000);
c1.makeCall(c1,3);
c1.top_up(90);
c1.display();
return 0;
}
5👍1
17&18
من تقديم الأستاذ ياسين❤️
السؤال يشرح الكود
ف اقرأ الكود بعد ما تقرأ السؤال
و كله تقريباً نفس شرح كلاس Bank بالقناة
اذا فهمت Bank فالباقي مجرد إضافات بسيطه عليه
1
سؤال الصباحي
8
شيئية OOP
سؤال الصباحي
الجواب مقدم من أحد طلبة الصباحي وفقهم الله :

#include <iostream>
using namespace std;

class Cuboid {
private:
double length;
double breadth;
double height;

public:
Cuboid(double l, double b, double h) {
length = l;
breadth = b;
height = h;
}

double Volume() {
return length * breadth * height;
}

Cuboid operator+(Cuboid& cuboid2){
Cuboid cuboid3(0, 0, 0);
cuboid3.length = length + cuboid2.length;
cuboid3.breadth = breadth + cuboid2.breadth;
cuboid3.height = height + cuboid2.height;
return cuboid3;
}
};


int main() {

Cuboid cuboid1(4, 3, 2);
Cuboid cuboid2(3, 1, 2);
Cuboid cuboid3(0, 0, 0);

cout << "cuboid1 : " << cuboid1.Volume() << endl;
cout << "cuboid2 : " << cuboid2.Volume() << endl;
cuboid3 = cuboid1 + cuboid2;
cout << "combinedCuboid : " << cuboid3.Volume() << endl;

return 0;
}
👍43
مثال عن polymorphism :

#include <iostream> 
using namespace std;

class Shape {
public:
virtual double area() = 0;
};


class Circle : public Shape {
private:
double radius;
public:
Circle(double r) {
radius = r;
}

double area() {
return 3.14 * radius * radius;
}
};


class Rectangle : public Shape {
private:
double length;
double width;
public:
Rectangle(double l, double w): length(l), width(w) {}

double area() {
return length * width;
}
};


int main() {
Circle circle(5);
Rectangle rectangle(4, 6);

cout << "Area in Circle : " << circle.area() << endl;
cout << "Area in Rectangle : " << rectangle.area() << endl;
return 0;
}
👍51
شيئية OOP
مثال عن polymorphism : #include <iostream> using namespace std; class Shape { public: virtual double area() = 0; }; class Circle : public Shape { private: double radius; public: Circle(double r) { radius = r; } double area() { return…
نفس فكرة وطريقة الملزمة :

#include <iostream>
using namespace std;

class Shape {
public:
virtual double area() = 0;
};


class Circle : public Shape {
private:
double radius;

public:
Circle(double r): radius(r){}

double area() {
return 3.14 * radius * radius;
}
};


class Rectangle : public Shape {
private:
double length;
double width;

public:
Rectangle(double l, double w): length(l), width(w) {}

double area() {
return length * width;
}
};


int main() {
Shape *Shape;
Circle circle(5);
Rectangle rectangle(4, 6);

Shape = &circle;
cout << "Area in Circle : " << Shape->area() << endl;
Shape = &rectangle;
cout << "Area in Rectangle : " << Shape->area() << endl;

return 0;
}
👍31
سؤال مختبر البرمجة
بتاريخ:
2024/4/20
شيئية OOP
سؤال مختبر البرمجة بتاريخ: 2024/4/20
#include <iostream>
using namespace std;

class cakestore{
public:

virtual void print()
{
cout<< "this is cake store"<<endl;
}
};


class chocolate: public cakestore {
public:

void print() {
cout<< "chocolate cake" << endl;
}
};


class vanilla: public cakestore {
public:

void print() {
cout<< "vanilla cake" << endl;
}
};


int main() {

chocolate typechocolate;
typechocolate.print();

vanilla typevanilla;
typevanilla.print();

/*
cakestore *caketype;

chocolate typecake;
caketype = &typecake;
caketype->print();

vanilla typevanilla;
caketype = &typevanilla;
caketype->print();
*/

return 0;
}
5👍1