《C++程序設(shè)計(jì)題目源碼(實(shí)驗(yàn)二)》由會(huì)員分享,可在線閱讀,更多相關(guān)《C++程序設(shè)計(jì)題目源碼(實(shí)驗(yàn)二)(6頁(yè)珍藏版)》請(qǐng)?jiān)谘b配圖網(wǎng)上搜索。
1、實(shí)驗(yàn)題目(共4題,第1題)
標(biāo)題:1.函數(shù)重載
時(shí)限:3000 ms
總時(shí)限:
內(nèi)存限制:10000 K
3000 ms
設(shè)計(jì)一菜單程序,利用函數(shù)重載實(shí)現(xiàn)員工月工資的計(jì)算,計(jì)算方法如 下:
描述:
(1)管理人員的月工資 =月薪一缺勤天數(shù) X月薪 + 22;
(2)銷售人員的月工資 =底薪+銷售金額 X提成比例;
(3)計(jì)件工人的月工資 =產(chǎn)品件數(shù) X每件報(bào)酬;
(4)計(jì)時(shí)工人的月工資 =工作小時(shí) X小時(shí)報(bào)酬;
職工類別及相關(guān)信息。
職工類別:1表示管理人員;2表示銷售人員;3表示計(jì)件工人;4表示
八] 計(jì)時(shí)工人;其余字符表示退出。
輸入:
相關(guān)信息:若為管理人
2、員,則輸入月薪和缺勤天數(shù);若為銷售人員,則 輸入底薪、銷售金額和提成比例;若為計(jì)件工人,則輸入產(chǎn)品件數(shù)和每 件報(bào)酬;若為計(jì)時(shí)工人,則輸入工作小時(shí)和小時(shí)報(bào)酬。
輸出:?jiǎn)T工月工資。
〈—―職工類別
輸入樣例:
5000.0 1 〈——月薪和缺勤天數(shù)
輸出樣例:
4772.73
1 .計(jì)算管理人員、銷售人員、計(jì)件工人、計(jì)時(shí)工人的月工資的函數(shù)原型 可以分別設(shè)計(jì)如下:
double getEarning(double salary, int absenceDays);
提示:
double getEarning(double baseSalary, double salesSum
3、, double rate);
double getEarning(int workPieces, double wagePerPiece);
double getEarning(double hours, double wagePerHour);
2.菜單程序設(shè)計(jì)如下:
int main()
{ ...
cout << "Please select..." << endl;
cout << "1: Manager." << endl;
cout << "2: Sales Man." << endl;
cout << "3: Pieces Worker." << endl;
4、
cout << "4: Hour-Worker." << endl;
cout << "Others: Quit" << endl;
cin >> sel;
switch(sel)
{
case 1:
cin >> ...;
cout << getEarning(...);
break;
case 2:
cin >> ...;
cout << getEarning(...);
break;
case 3:
cin >> ...;
cout << getEarning(...);
break;
case 4:
cin >> ...;
cout << get
5、Earning(...);
break;
default:
break;
}
return 0;
}
來源:
? #include
? using namespace std;
?
? double getEarning(double salary, int absenceDays)
? {
? return salary-salary*absenceDays/22;
? }
? double getEarning(double baseSalary, double salesSum, double rate)
? {
? return
6、baseSalary+salesSum*rate;
? }
? double getEarning(int workPieces, double wagePerPiece)
? {
? return wagePerPiece*workPieces;
? }
? double getEarning(double hours, double wagePerHour)
? {
return hours*wagePerHour;
int main() cout << "Please select..." << endl;
cout << "1: Manager." << endl;
7、
cout << "2: Sales Man." << endl;
cout << "3: Pieces Worker." << endl;
cout << "4: Hour-Worker." << endl;
cout << "Others: Quit" << endl;
int sel;
cin >> sel;
switch(sel)
{
case 1:
double salary;
int absenceDays;
cin>>salary>>absenceDays;
cout << getEarning(salary,absenceDays); break;
8、case 2:
double baseSalary,salesSum,rate;
cin>>baseSalary>>salesSum>>rate;
cout << getEarning(baseSalary,salesSum,rate); break;
case 3:
int workPieces;
? double wagePerPiece;
? cin>>workPieces>>wagePerPiece;
? cout << getEarning(workPieces,wagePerPiece);
? break;
? case 4:
? double hours,
9、wagePerHour;
? cin>>hours>>wagePerHour;
? cout << getEarning(hours,wagePerHour);
? break;
? default:
? break;
? }
? return 0;
? }
實(shí)驗(yàn)題目(共4題,第2題)
標(biāo)題:
2.引用傳遞
3000 ms
內(nèi)存限制:10000 K
總時(shí)限:3000 ms
設(shè)計(jì)一個(gè)函數(shù),將兩個(gè)浮點(diǎn)數(shù)傳入,然后通過引用把其和、差、積傳出。
中曲I術(shù): 一、“,一一.,._. _ _ _ _ _
函數(shù)原型如下: void Math(float a,fl
10、oat b,float &sum,float
? #include
? #include
? using namespace std;
?
? void Math(float a,float b,float &sum,float &sub,float &pro)
? {
? sum=a+b;
? sub=a-b;
? pro=a*b;
? }
? int main()
? {
? float a,b,sum,sub,pro;
? cin>>a>>b;
? Math(a,b,sum,sub,pro);
? cout<
11、m<<" "<
? template
? void swap(Type &a,Type &b)
? {
? Type x;
? x=a;
? a=b;
? b=x;
? }
? int main()
? {
? int a,b;
? char x,y;
? std::cin>>a>>b;
? swap(a,b);
std::cout<
12、d::cin>>x>>y;
swap(x,y);
std::cout<
13、at distancefloat x1,float y1,float z1, float x2=0,float y2=0,float z2=0);
來源:
#include
? using namespace std;
float distance(float x1,float y1,float z1, float x2=0,float y2=0,float z2=0) {
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
}
? int main()
? {
? float x1,y1,z1,x2,y2,z2;
? cin>>x1>>y1>>z1>>x2>>y2>>z2;
? cout<