-أكتب برنامج يعرض للمستخدم قائمة إما رسم مربّع أو مستطيل أو خروج ، إذا اختار المستخدم المربع يطلب منه إدخال طول ضلع المربع ، وإذا اختار المستطيل يطلب منه إدخال الطول والعرض .
يجب استخدام مفهوم functions’ prototypes and functions’ overloading في الحل .
-استخدم ” * ” للرسم .
الحل:
#include <iostream> using namespace std; void drow(); void drow(int); int main() { int choice; do{ cout << "Welcome to my shapes!" << endl; cout << "Please select a shape to draw: " << endl; cout << "1- Square \n2- Rectangle \n3- Exit program" << endl; cout << "Your choice: "; cin >> choice; switch (choice) { case 1://Square int hw_s; cout << "Please enter height or width of the square: "; cin >> hw_s; drow(hw_s); break; //Rectangle case 2:drow(); break; } } while (choice == 1 || choice == 2); system("pause"); return 0; } void drow(int x) { //Square for (int counter = x; counter > 0; counter--) { for (int i = 1; i <= x; i++) cout << "*"; cout << endl; } } void drow() { //rectangle int h_r, W_r; cout << " Enter the height of the rectangle: "; cin >> h_r; cout << " Enter the width of the rectangle: "; cin >> W_r; for (int count = h_r; count > 0; count--) { for (int i = 1 ; i <= W_r; i++) cout << "*"; cout << endl; } }
Advertisements