اذهب إلى المحتوى

Enas Wawy

الأعضاء
  • المساهمات

    2
  • تاريخ الانضمام

  • تاريخ آخر زيارة

كل منشورات العضو Enas Wawy

  1. #include<iostream> #include<fstream> #include<string> using namespace std; class Dealer {protected: string Name; public: Dealer( ) { Name = "Unknown"; } string get_name() { return Name; } void set_data(string name) { name = Name; } }; class PlayStation { int No; protected: float price; public: PlayStation(){} PlayStation( string a) { cout << "No: "; cin >> No; cout << "price: "; cin >> price; } float get_price() { return price; } void set_price(float p) { price = p; } }; class Invoice :public Dealer { float Total; public: PlayStation PlayStations[5] ; Invoice() { for (int i = 0; i < 5; i++) { Total += PlayStations[i].get_price(); } if (Total < 0) { Total = 0; } } void ReadPrices() { float p; for (int i = 0; i < 5; i++) { cout << "Price: "; cin >> p; PlayStations[i].set_price(p); } } float GetTotal() { for (int i = 0; i <5; i++) { Total += PlayStations[i].get_price(); } return Total; } float GetMax() { float max=PlayStations[0].get_price(); for(int i=0;i<2;i++){ if (max<PlayStations[i].get_price()) max<PlayStations[i].get_price();} return max; } void print(){ cout<<"Name:"<<Name<<endl; } void print(string name_file) { ofstream read; read.open("Date.txt"); read << "Name: " << get_name()<<endl; read << "Total: " << Total << endl<<endl; read.close(); } }; int main() { Invoice n[2] ; for (int i = 0; i < 2; i++) { n[i].ReadPrices(); cout<<"Total :"<<n[i].GetTotal()<<endl; cout<<"Maximam :"<<n[i].GetMax()<<endl; n[i].print(); n[i].print("Date.txt"); } return 0; } #include<iostream> #include<fstream> #include<string> using namespace std; class Dealer {protected: string Name; public: Dealer( ) { Name = "Unknown"; } string get_name() { return Name; } void set_data(string name) { name = Name; } }; class PlayStation { int No; protected: float price; public: PlayStation(){} PlayStation( string a) { cout << "No: "; cin >> No; cout << "price: "; cin >> price; } float get_price() { return price; } void set_price(float p) { price = p; } }; class Invoice :public Dealer { float Total; public: PlayStation PlayStations[5] ; Invoice() { for (int i = 0; i < 5; i++) { Total += PlayStations[i].get_price(); } if (Total < 0) { Total = 0; } } void ReadPrices() { float p; for (int i = 0; i < 5; i++) { cout << "Price: "; cin >> p; PlayStations[i].set_price(p); } } float GetTotal() { for (int i = 0; i <5; i++) { Total += PlayStations[i].get_price(); } return Total; } float GetMax() { float max=PlayStations[0].get_price(); for(int i=0;i<2;i++){ if (max<PlayStations[i].get_price()) max<PlayStations[i].get_price();} return max; } void print(){ cout<<"Name:"<<Name<<endl; } void print(string name_file) { ofstream read; read.open("Date.txt"); read << "Name: " << get_name()<<endl; read << "Total: " << Total << endl<<endl; read.close(); } }; int main() { Invoice n[2] ; for (int i = 0; i < 2; i++) { n[i].ReadPrices(); cout<<"Total :"<<n[i].GetTotal()<<endl; cout<<"Maximam :"<<n[i].GetMax()<<endl; n[i].print(); n[i].print("Date.txt"); } return 0; }
  2. بدي حدا يحللي هاد السؤال ضروري حاولت ما زبط معي؟ 1- قم بإنشاء صنف (Dealer) وفق التالي: a. المتغيرات: i. الاسم -:Name محمي من نوع نص. b. الدوال: i. بناء يستقبل معامل ويقوم بوضع قيم ابتدائية للاسم. القيمة الافتراضية للمعامل هي "Unknown". ii. دالة عامة ترجع قيمة الاسم. iii. دالة عامة تستقبل معامل وتغير من خلاله قيمة الاسم. 2- قم بإنشاء صنف (PlayStation) وفق التالي: a. المتغيرات: i. الرقم - :No خاص من نوع رقم صحيح. ii. السعر - :price محمي رقمي عشري. b. الدوال: i. بناء يقوم بقراءة قيم للمتغيرات من خلال لوحة المفاتيح. ii. دالة عامة ترجع قيمة السعر. iii. دالة عامة تستقبل معامل وتغير من خلاله قيمة السعر. 3- قم بإنشاء صنف (Invoice) يرث من الصنف (Dealer) وراثة عامة وفق التالي: a. المتغيرات: i. :PlayStations عامة مصفوفة مكونة من 5 كائنات (PlayStation). ii. Total: خاص رقمي عشري. b. الدوال: i. ReadPrices(): عامة وتقوم بقراءة قيم عناصر المصفوفة (PlayStations) . ii. GetTotal(): عامة وتحسب مجموع الاسعار للمصفوفة وتخزينه داخل المتغير (Total) ثم تقوم بارجاعه. iii. GetMax(): عامة ترجع اعلى الاسعار للمصفوفة. iv. بناء يقوم بحساب مجموع الاسعار للمصفوفة وتخزينه داخل المتغير (Total). v. :Print() عامة وتطبع على الشاشة جميع المتغيرات المحلية والموروثة. vi. بين مفهوم إعادة التحميل مستخدما الدالة (Print) باستقبالها اسم ملف وكتابة جميع المتغيرات المحلية والموروثة داخل الملف. 4- الدالة الرئيسية: a. انشاء مصفوفة كائنات ديناميكيا من نوع (Invoice) تتكون من أي عدد من عندك. b. استدعاء جميع الدوال الخاصة والموروثة بالكائن السابق.
×
×
  • أضف...