当前位置:文档之家› 面向对象程序设计C试验题目Word版

面向对象程序设计C试验题目Word版

面向对象程序设计C试验题目Word版
面向对象程序设计C试验题目Word版

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 << getEarning(...);

break;

default:

break;

}

return 0;

}

来源:

#include

using namespace std;

double getEarning(double salary ,int absenceDays)

{

return (salary -salary*absenceDays/22);

}// admin

double getEarning(double baseSalary ,double salesSum,double rate) {

return (baseSalary + salesSum*rate);

}

double getEarning(int workPieces,double wagePerPiece)

{

return (workPieces*wagePerPiece);

}

double getEarning(double hours ,double wagePerHour)

{

return (hours*wagePerHour);

}

int main()

{

int kind = 0 ;

cout << "Please select..." << endl;

cout << "1: Manager." << endl;

cout << "2: Sales Man." << endl;

cout << "3: Pieces Worker." << endl;

cout << "4: Hour-Worker." << endl;

cout << "Others: Quit" << endl;

cin >> kind ;

switch(kind)

{

case 1:

{

double salary ;

int abDays;

cin>>salary>>abDays;

cout<

break;

}

case 2:

{

double base ;

double salesSum;

double rate;

cin>>base>>salesSum>>rate;

cout<

break;

}

case 3:

{

int workPieces;

double wagePerPiece;

cin>>workPieces>>wagePerPiece;

cout<

break;

}

case 4:

{

double hours;

double wagePerHour;

cin>>hours>>wagePerHour;

cout<

break;

}

default:

break;

}

// cout<

// cout<

// cout<

// cout<

return 0 ;

}

#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 sum = 0 ;

float sub = 0 ;

float pro = 0 ;

float a = 0 ;

float b = 0 ;

cin>>a>>b;

Math(a,b,sum,sub,pro);

cout<

}

#include

using namespace std;

template

T cg(T &a ,T& b)

{

T c ;

c = a ;

a =

b ;

b =

c ;

}

int main()

{

int a = 0 ;

int b = 0 ;

char c = 0 ;

char d = 0 ;

cin>>a>>b>>c>>d;

cout<

return 0 ;

}

#include

#include

using namespace std;

float distance(float x1,float y1,float z1,float x2=0,float y2=0,float z2=0) {

return sqrt(pow(x1-x2,2)+pow(y1-y2,2)+pow(z1-z2,2));

}

int main()

{

float x1 = 0 ;

float x2 = 0 ;

float y1 = 0 ;

float y2 = 0 ;

float z1 = 0 ;

float z2 = 0 ;

cin>>x1>>y1>>z1>>x2>>y2>>z2;

cout<

cout<

return 0 ;

}

实习三

标题:类的定义_静态常量时限:3000 ms

内存限制:10000 K

总时限:3000 ms

描述:设计并实现一个圆柱类Cylinder,要求:

(1)设计两个double型的私有数据成员:高度height和底圆半径radius。

(2)设计一个double型的公有静态常量数据成员pi(其值初始化为3.1415926),以及一个获取该常量的公有静态成员函数GetPI。

(3)在构造函数的初始化列表中初始化高度height和底圆半径radius。

(4)设计用于获取半径的成员函数GetRadius、获取高度的成员函数GetHeight、设置半径的成员函数SetRadius、设置高度的成员函数SetHeight。

(5)设计用于计算圆柱体积的成员函数Volume()、计算圆柱表面积的成员函数Area。

在main函数中:

根据输入的高度和半径构造圆柱对象,并输出圆柱的基本信息、体积和表面积。

输入:圆柱的高度和底圆半径

输出:圆周率pi、圆柱高度、底圆半径、圆柱的体积和表面积

输入样例: 2.0 1.0

输出样例:pi=3.14159, height=2, radius=1:volume=6.28319, area=18.8496 #include

using namespace std;

class Cylinder

{

private:

double height,radius;

public:

static const double Pi=3.1415926;

Cylinder(double a=0,double b=0)

{

height=a;

radius=b;

}

double GetPI()

相关主题
文本预览
相关文档 最新文档