Forwarded from تجمع بؤساء الهندسة²⁴⁻²³
تجمع بؤساء الهندسة²⁴⁻²³
declare a struct called personweight with a member variables name and weight. the struct should have an implementation to print a message " person-name you are overweight " if the person's weight is over 75kg, otherwise print a message " person-name you are…
هذا الكوز بصيغة Class الي طبقها دكتور ضياء خلال المحاضرة :
#include <iostream>
using namespace std;
class personweight {
public :
string name;
float weight;
string gender;
void printStatus() {
if ( (weight > 80 && gender == "male") || (weight > 65 && gender == "female") ) {
cout << name << " you are overweight" << endl;
} else {
cout << name << " you are fit" << endl;
}
}
};
int main() {
personweight person1 = {"am_kean", 56, "female"};
personweight person2 = {"abo_kean", 89, "male"};
person1.printStatus();
person2.printStatus();
return 0;
}
❤1
Forwarded from تجمع بؤساء الهندسة²⁴⁻²³
CoE_123_Object_oriented_programming_Exercises_Students_version.pdf
1 MB
تمارين برمجة
من دكتور ضياء
من دكتور ضياء
❤1🍓1
Ex1 :
Design a health care application to check the blood pressure of a patients. The application has a struct called patientPressure with a member variable (name, age, gender). Implement a method to issue the following message:
1- “name your blood pressure is high” if the systolic blood pressure is over 120mm Hg.
2- “name your blood pressure is normal” if the systolic blood pressure is between (100-120) mm Hg.
3- “name your blood pressure is low” if the systolic blood pressure is less 100 mm Hg.
Note: Instantiate an object called patient of type patientPressure.
Design a health care application to check the blood pressure of a patients. The application has a struct called patientPressure with a member variable (name, age, gender). Implement a method to issue the following message:
1- “name your blood pressure is high” if the systolic blood pressure is over 120mm Hg.
2- “name your blood pressure is normal” if the systolic blood pressure is between (100-120) mm Hg.
3- “name your blood pressure is low” if the systolic blood pressure is less 100 mm Hg.
Note: Instantiate an object called patient of type patientPressure.
#include <iostream>
using namespace std;
struct patientPressure {
string name;
int age;
string gender;
void issue(int pressure) {
if(pressure > 120) {
cout<< name << " your blood pressure is high " << endl;
}
if(pressure >= 100 && pressure <= 120) {
cout<< name << " your blood pressure is normal " << endl;
}
if(pressure < 100) {
cout<< name << " your blood pressure is low " << endl;
}
}
};
int main()
{
patientPressure patient1 = {"salam", 34, "male"};
patient1.issue(110);
return 0;
}
❤5✍1👍1
EX2 :
A health care application, that specializes in tracking the weight of persons, has a class called personWeight with three variables (name, gender, and weight). Implement a method to give an appropriate message according to the following conditions:
1- “name you are overweight” if the person is male and his weight more than 80 kg else “you
are fit”.
2- “name you are overweight” if the person is female and his weight more than 60 kg else
“you are fit”.
Note: Instantiate an object called person of type personWeight. Use constructor to initialize the variables.
A health care application, that specializes in tracking the weight of persons, has a class called personWeight with three variables (name, gender, and weight). Implement a method to give an appropriate message according to the following conditions:
1- “name you are overweight” if the person is male and his weight more than 80 kg else “you
are fit”.
2- “name you are overweight” if the person is female and his weight more than 60 kg else
“you are fit”.
Note: Instantiate an object called person of type personWeight. Use constructor to initialize the variables.
#include <iostream>
using namespace std;
class personweight {
protected :
string name;
float weight;
string gender;
public :
personweight ( string n, float w, string g ) {
name = n;
weight = w;
gender = g;
}
void printStatus() {
if ( (weight > 80 && gender == "male") || (weight > 60 && gender == "female") ) {
cout << name << " you are overweight" << endl;
} else {
cout << name << " you are fit" << endl;
}
}
};
int main() {
personweight person1 = {"am_kean", 56, "female"};
personweight person2 = {"abo_kean", 89, "male"};
person1.printStatus();
person2.printStatus();
return 0;
}
👍8
EX3 :
A health care application, that specializes in tracking the weight of persons, has a class called personWeight with three variables (name, gender, and weight). Implement a method to give an appropriate message according the following conditions:
1- “name you are overweight” if the person is male and his weight more than 80 kg else “you
are fit”.
2- “name you are overweight” if the person is female and his weight more than 60 kg else
“you are fit”.
Note: Instantiate an object called person of type personWeight. Use setter function to initialize the variables
A health care application, that specializes in tracking the weight of persons, has a class called personWeight with three variables (name, gender, and weight). Implement a method to give an appropriate message according the following conditions:
1- “name you are overweight” if the person is male and his weight more than 80 kg else “you
are fit”.
2- “name you are overweight” if the person is female and his weight more than 60 kg else
“you are fit”.
Note: Instantiate an object called person of type personWeight. Use setter function to initialize the variables
#include <iostream>
using namespace std;
class personweight {
protected :
string name;
float weight;
string gender;
public :
void setinf( string n, float w, string g ) {
name = n;
weight = w;
gender = g;
}
void printStatus() {
if ( (weight > 80 && gender == "male") || (weight > 60 && gender == "female") ) {
cout << name << " you are overweight" << endl;
} else {
cout << name << " you are fit" << endl;
}
}
};
int main() {
personweight person1;
person1.setinf ("am_kean", 56, "female");
personweight person2;
person2.setinf ("abo_kean", 89, "male");
person1.printStatus();
person2.printStatus();
return 0;
}
👍5❤2
Ex4 :
Create a class for a bank_account that includes the account_holder's_name, account_number, and balance. Implement member functions for deposit (as member inside the class), withdrawal (as member outside the class), and displaying (as a void friend function) the current balance. Instantiate an object called client of type bank_account. Use constructor to initialize the variables.
Create a class for a bank_account that includes the account_holder's_name, account_number, and balance. Implement member functions for deposit (as member inside the class), withdrawal (as member outside the class), and displaying (as a void friend function) the current balance. Instantiate an object called client of type bank_account. Use constructor to initialize the variables.
#include <iostream>
using namespace std;
class bank {
private :
string AccountHolderName;
int AccountNumber;
double balance;
public:
bank ( string AH, int AN, double B) {
AccountHolderName = AH;
AccountNumber = AN;
balance = B;
}
void deposit (double amount) {
balance += amount;
}
void withDrawal(double amount);
friend void display (bank bank);
};
void bank::withDrawal(double amount) {
balance -= amount;
}
void display (bank bank) {
cout << "your balance is : " << bank.balance << endl;
};
int main()
{
bank client = {"mogo", 78904, 1090};
client.deposit(24.5);
client.withDrawal(9.5);
display(client);
return 0;
}
❤8👍5
Ex5 :
Create a class for a bank_account that includes the account_holder's_name, account_number, and balance. Implement member functions for deposit (as member inside the class), withdrawal (as member outside the class), and displaying (as a void friend function) the current balance. Instantiate an object called client of type bank_account. Implement setter function to initialize the variables.
Create a class for a bank_account that includes the account_holder's_name, account_number, and balance. Implement member functions for deposit (as member inside the class), withdrawal (as member outside the class), and displaying (as a void friend function) the current balance. Instantiate an object called client of type bank_account. Implement setter function to initialize the variables.
#include <iostream>
using namespace std;
class bank {
protected :
string AccountHolderName;
int AccountNumber;
double balance;
public :
void setinf ( string AH, int AN, double B) {
AccountHolderName = AH;
AccountNumber = AN;
balance = B;
}
void deposit (double amount) {
balance += amount;
}
void withDrawal(double amount);
friend void display (bank bank);
};
void bank::withDrawal(double amount) {
balance -= amount;
}
void display (bank bank) {
cout << "your balance is : " << bank.balance << endl;
};
int main()
{
bank client;
client.setinf("mogo", 78904, 1090);
client.deposit(24.5);
client.withDrawal(9.5);
display(client);
return 0;
}
👍3❤2
Ex6 :
Create a class for a bank_account that includes the account_holder's_name, account_number, and balance. Implement member functions for deposit (as member inside the class), withdrawal (as member outside the class), and displaying (as a void friend function) the current balance. Instantiate an object called client of type bank_account. Declare a pointer to invoke the functions.
Create a class for a bank_account that includes the account_holder's_name, account_number, and balance. Implement member functions for deposit (as member inside the class), withdrawal (as member outside the class), and displaying (as a void friend function) the current balance. Instantiate an object called client of type bank_account. Declare a pointer to invoke the functions.
#include <iostream>
using namespace std;
class Bank {
protected :
string AccountHolderName;
int AccountNumber;
double balance;
public :
Bank (string AHN, int AN, double B) {
AccountHolderName = AHN;
AccountNumber = AN;
balance = B;
}
void deposit(double amount) {
balance += amount;
}
void withdrawal(double amount);
friend void display(Bank Bank);
};
void Bank::withdrawal (double amount) {
balance -= amount;
}
void display(Bank Bank) {
cout << " AccountHolderName : " << Bank.AccountHolderName << ", AccountNumber : " << Bank.AccountNumber << " , balance : " << Bank.balance << endl;
}
int main()
{
Bank client = {"mogo", 98056, 70.53};
Bank* ptr = &client;
ptr -> deposit(15.22);
ptr -> withdrawal(13.45);
display(*ptr);
return 0;
}
👍3❤2
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.
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;
}
👍3❤1🎄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.
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.
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;
}
👍2❤1
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.
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;
}
👍3❤1
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.
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;
}
👍3❤1
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