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.
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;
}
👍3❤1
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
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.
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.
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
شيئية OOP
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…
عدكم هاي الجزئية خطوة زايدة
طكوها سلاش //
ما تأثر على عمل الكود
طكوها سلاش //
ما تأثر على عمل الكود
❤1
شيئية 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;
}
👍4❤3
مثال عن 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;
}
👍5❤1
شيئية 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;
}
👍3❤1
شيئية 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
تجمع بؤساء الهندسة²⁴⁻²³
تغيير قيمة المعاملات باستخدام البوينتر : #include <iostream> using namespace std; int p ( int *ptr){ *ptr+= 1; return *ptr; } int main() { int m = 5; cout << p(&m) << endl; cout << m << endl; cout << p(&m) << endl; }
منا وانت نازل مادتنا لهذا الكورس :
أمثلة
الكوز
اسئلة المختبر
ال18 سؤال
اسئلة من العام السابق
و بالنسبة لشروحات المادة ف اليوتيوب مليئ بالمقاطع تابع الي تفهم عليه
+انا ناشر لعادل نسيم :
في نهاية القائمة ( بوينتر، رفرنس، ستركت، Inline ) :
https://youtube.com/playlist?list=PLCInYL3l2AajFAiw4s1U4QbGszcQ-rAb3&si=3vYmdgld5-Dwv_UF
شرح لـ OOP :
https://youtube.com/playlist?list=PLCInYL3l2Aaiq1oLvi9TlWtArJyAuCVow&si=RPVhIKrXhbp-a8Il
أمثلة
الكوز
اسئلة المختبر
ال18 سؤال
اسئلة من العام السابق
و بالنسبة لشروحات المادة ف اليوتيوب مليئ بالمقاطع تابع الي تفهم عليه
+انا ناشر لعادل نسيم :
في نهاية القائمة ( بوينتر، رفرنس، ستركت، Inline ) :
https://youtube.com/playlist?list=PLCInYL3l2AajFAiw4s1U4QbGszcQ-rAb3&si=3vYmdgld5-Dwv_UF
شرح لـ OOP :
https://youtube.com/playlist?list=PLCInYL3l2Aaiq1oLvi9TlWtArJyAuCVow&si=RPVhIKrXhbp-a8Il
❤3
شيئية OOP
منا وانت نازل مادتنا لهذا الكورس : أمثلة الكوز اسئلة المختبر ال18 سؤال اسئلة من العام السابق و بالنسبة لشروحات المادة ف اليوتيوب مليئ بالمقاطع تابع الي تفهم عليه +انا ناشر لعادل نسيم : في نهاية القائمة ( بوينتر، رفرنس، ستركت، Inline ) : https://youtub…
#include <iostream>
using namespace std;
class Box {
private:
double length;
double breadth;
double height;
public:
Box(double l, double b, double h) {
length = l;
breadth = b;
height = h;
}
double Volume() {
return length * breadth * height;
}
int compare(Box box) {
return this->Volume() > box.Volume();
}
};
int main(void)
{
Box Box1(3.3, 1.2, 1.5);
Box Box2(8.5, 6.0, 2.0);
if(Box1.compare(Box2)) {
cout << "Box2 is smaller than Box1" <<endl;
}
else {
cout << "Box2 is equal to or larger than Box1" <<endl;
}
return 0;
}
هاي من الملزمة بس اتوقع يجيبها لأن ما طبقناها
👍6
شيئية OOP
Photo
السؤال الأول /
1- instance
2- memory
3- name
4- member
5- this ->
6- early
7- virtual , implementation
☆●☆
السؤال الثاني /
☆●☆
السؤال الثالث /
1- instance
2- memory
3- name
4- member
5- this ->
6- early
7- virtual , implementation
☆●☆
السؤال الثاني /
#include<iostream>
using namespace std;
class Cars {
private:
string brandN;
int maxspeed, fuelC, safetyR;
public:
Cars(string b,int m,int f,int s):brandN(b),maxspeed(m),fuelC(f),safetyR(s){}
bool operator>(const Cars& other) const {
int pointA=0, pointB=0;
if (maxspeed>other.maxspeed) {
pointA++;
} else {
pointB++;
}
if (fuelC<other.fuelC) {
pointA++;
} else {
pointB++;
}
if (safetyR>other.safetyR) {
pointA++;
} else {
pointB++;
}
return pointA > pointB;
}
};
int main() {
Cars BMW("BMW",300,5,10);
Cars KIA("KIA",200,4,5);
if(BMW > KIA) {
cout <<"BMW has a higher assessment"<< endl;
}else{
cout <<"KIA has a higher assessment"<< endl;
}
return 0;
}
☆●☆
السؤال الثالث /
#include<iostream>
using namespace std;
class customer
{
protected:
string name;
int phonenumber;
int credit;
public:
customer(string n,int ph,int c):name(n),phonenumber(ph),credit(c){}
virtual void call() {
cout << " virtual calling " << endl;
};
};
class prepaid : public customer
{
public:
prepaid(string n,int ph,int c):customer(n,ph,c){}
void call() {
cout<<"prepaid make call"<<endl;
}
};
class postpaid : public customer
{
public:
postpaid(string n,int ph,int c):customer(n,ph,c){}
void call()
{
cout<<"postpaid make call"<<endl;
}
};
int main()
{
prepaid call1("memo",3579,300);
postpaid call2("oeom",2468,600);
customer* ptr=&call1;
ptr->call();
ptr=&call2;
ptr->call();
}
👍3❤2