幫忙寫Dev-C++的題目
試寫一個程式, 使用函數的多載, 及大型程式專案的檔案分割方式, 來開發一個專案.
請開發一專案, 包括.h檔, 函式的cpp檔, 及主程式cpp檔.
.h檔案宣告函數的標頭. 使用函數的多載, 宣告三個函數, 使用同樣的檔名 GetArea, 三個函數分別可計算 長方型, 圓型, 和梯型的面積.
函式的cpp檔, 就實作三個函數的程式碼
-計算長方型的函數可接受2個整數參數, 計算長方型面積後, 回傳面積整數值.
-計算圓型的函數可接受1個浮點數參數, 計算圓型面積後, 回傳面積浮點數值.
-計算梯型的函數可接受3個整點數參數, 計算梯型面積後, 回傳面積整數值.
主程式cpp檔案中, 請使用迴圈, 詢問使用者要計算那一種形狀的面積, 然後再詢問, 所需要的參數 (長寬, 或半徑, 或上底下底和高) . 然後, 呼叫函數, 算出面積, 顯示出來. 使得可以重複執行上面的功能, 直到輸入0結束程式.
請大家幫幫忙~謝謝
不是我要的答案....
其中的長方形函數
main ()
{
int a,b,c;
cout<<"輸入題目上的數值,我將為您算出長方形面積^^\n"<<"請輸入長:";
cin>>a;
cout<<"請輸入寬:";
cin>>b;
c=a*b;
cout<<"此長方形面積為:"<<<"\n";
我想要類似上面cin和cout的程式碼= =
謝謝大大
你的程式執行和條件內容是我需要的沒錯
因為你那種我看不懂ˇˇ
所以我想要的是類似cin和cout的程式碼
感謝大大
不用了
不過還是辛苦你了 謝謝
1 個解答
- 1 0 年前最佳解答
你好!以下是我為你解答的程式碼!
#include<stdlib.h>
#include<stdio.h>
void aaa();
void bbb();
void ccc();
int main(void){
int x;
for(;;){
printf("請選擇要計算的面積(按1 長方形,按2 圓形,按3 梯型,按0 結束程式)\n");
scanf("%d",&x);
switch(x){
case 1:
printf("長方形面積\n");
aaa();
break;
case 2:
printf("圓形面積\n");
bbb();
break;
case 3:
printf("梯形面積\n");
ccc();
break;
}
if(x==0){
break;
}
}
system("pause");
return 0;
}
void aaa(){
float a,b;
printf("請輸入長\n");
scanf("%f",&a);
printf("請輸入寬\n");
scanf("%f",&b);
printf("長方形面積=%f\n",a*b);
}
void bbb(){
float a;
float b=3.14;
printf("請輸入圓的半徑\n");
scanf("%f",&a);
printf("圓形面積=%f\n",a*a*b);
}
void ccc(){
float a,b,c;
printf("請輸入上底\n");
scanf("%f",&a);
printf("請輸入下底\n");
scanf("%f",&b);
printf("請輸入高\n");
scanf("%f",&c);
printf("梯形面積=%f\n",((a+b)*c)/2);
}
希望解決了妳的疑問!
如果有任何不懂的地方需要註解,歡迎提問!
2010-04-08 11:25:46 補充:
你好!
請問是因為我程式執行錯誤,還是內容不符合你的要求!
我需要你的詳細條件,好讓我能揣摩一下妳想要的結果!
謝謝!
2010-04-09 12:43:19 補充:
好的!As your wish!以下是新的程式碼!
#include
#include
#define PI 3.14
using namespace std;
class Shape
{
public:
float Shape::GetArea(float radious)
{
return float (PI*radious*radious);
}
2010-04-09 12:44:12 補充:
float Shape::GetArea(float side1, float side2, float side3)
{
float average=(side1+side2)*side3/2;
return average;
}
float Shape::GetArea(float side1, float side2)
{
return float (side1 * side2);
}
};
2010-04-09 12:44:28 補充:
class Triangle : public Shape
{
public:float side1, side2 ,side3;
public:
Triangle()
{
cout<<"輸入梯形上底下底和高:"<
>side1>>side2>>side3;
}
};
2010-04-09 12:44:42 補充:
class Circle : public Shape
{
public:float radious;
public:
Circle()
{
cout<< "輸入圓的半徑:"<
>radious;
}
};
2010-04-09 12:46:01 補充:
剩下的我貼在意見 因為字數限制!
2010-04-09 12:46:19 補充:
class Rectangle : public Shape
{
public:float side1, side2;
public:
Rectangle()
{
cout<<"輸入長方形的長和寬:"<
>side1>>side2;
}
};
2010-04-09 12:46:58 補充:
int main()
{
int num;
cout<<"請選擇你要計算面積的圖形:"<<<"1.梯形 2.圓形 3.矩形"<
>num;
switch(num){
case 1:{
Triangle* T = new Triangle;
cout<<"梯形的面積為:"< GetArea(T->side1, T->side2, T->side3)<
2010-04-09 12:47:58 補充:
}
}while (num != 1|| num != 2|| num != 3);
return 0;
}
2010-04-09 12:52:26 補充:
好難貼!我直接寄信給你!給我你的信箱吧!
謝謝!
參考資料: 我