學(xué)校信息系統(tǒng):
假定學(xué)生與老師共用一套編號、姓名系統(tǒng),作為基類Person。學(xué)生Student類專有數(shù)據(jù)排名,教師Teacher類專有數(shù)據(jù)科目(chinese、math、English)。
輸入數(shù)據(jù)包含x、y、z、t。x為5位編號,y為姓名,z為專有數(shù)據(jù),t為類別(學(xué)生為1,教師為2)。
輸出數(shù)據(jù)為“Student:x y z”或者“Teacher:x y z”(無引號)。
#includeusing namespace std;
class Person{protected:
double m_id;
string m_name;
public:
Person(double id,string name):m_id(id),m_name(name){};
};
class Student:public Person{private:
string p_data;
public:
Student(double id,string name,string data):Person(id,name),p_data(data){};
void printstudent(){ cout<<"Student:"<private:
string p_project;
public:
Teacher(double id,string name,string project):Person(id,name),p_project(project){};
void printteacher(){ cout<<"Teacher:"<int t;
double x;
string y,z;
cin>>x >>y >>z >>t;
Student s1(x,y,z);
Teacher t1(x,y,z);
if (t==1)
s1.printstudent();
else
t1.printteacher();
}
計算圖形面積:
要求建立一個形狀類Shape作為基類,圓類Circle和矩形類Rectangle繼承于形狀類Shape,并由此求出面積。具體要求如下:
(1)形狀類Shape:包含圖形參數(shù)x、y。對于圓,x和y均表示圓的半徑(保證輸入相等),而對于矩形,x表示矩形的長,y表示矩形的寬。同時包含初始化函數(shù)。
(2)圓類Circle:包含求面積函數(shù)。
(3)矩形類Rectangle:包含求面積函數(shù)。
本題中,Π取3.14。
輸入包含三個數(shù),x、y、t,x、y為圖形參數(shù)(浮點型),t為圖形類別(整數(shù)型),1表示圓形,2表示矩形。
輸出為一個數(shù),為圖形面積,保留3位小數(shù)。
#include#includeconst double PI=3.14;
using namespace std;
class Shape{protected:
double x;
double y;
public:
Shape(double _x,double _y):x(_x),y(_y){};
};
class Circle:public Shape{public:
Circle(double r,double _r):Shape(r,_r){};
void getarea(){ cout<public:
Rectangle(double l,double w):Shape(l,w){};
void getarea(){ cout<double x,y;
int t;
cin >>x >>y >>t;
Circle c(x,y);
Rectangle r(x,y);
if (t==1)
c.getarea();
else
r.getarea();
}
計算車重:
編寫一個程序,其中有一個基礎(chǔ)汽車類Vehicle,它具有一個需要傳遞參數(shù)的構(gòu)造函數(shù),類中的數(shù)據(jù)成員:車輪個數(shù)wheels和車重weight為保護(hù)屬性;小車類Car私有繼承于汽車類Vehicle,其中包含載人數(shù)passager_load;卡車類Truck私有繼承于汽車類Vehicle,其中包含載人數(shù)passager_load和載重量payload。
輸入數(shù)據(jù)包含a、b、c、d、t。a為車輪數(shù),b為車重,c為載人數(shù),d為載重量,t為類別(1為小車,2為卡車)。
輸出格式為“wheels=x weight=y”(無引號,x、y為計算得數(shù)據(jù),其中重量weight是總重,包含車重、人重和貨物重,單個人重量記為65kg)
#includeusing namespace std;
class Vehicle{protected:
double wheels;
double weight;
public:
Vehicle(double wl,double wh):wheels(wl),weight(wh){}
};
class Car:private Vehicle{private:
double passager_load;
public:
Car(double wl,double wh,double pl):Vehicle(wl,wh),passager_load(pl){};
void car_load(){ cout<<"wheels="<private:
double passager_load;
double payload;
public:
Truck(double wl,double wh,double pl,double pa):Vehicle(wl,wh),passager_load(pl),payload(pa){};
void truck_load(){ cout<<"wheels="<double a,b,c,d;
int t;
cin>>a>>b>>c>>d>>t;
if (t==1){Car c1(a,b,c);
c1.car_load();
}
else{Truck t1(a,b,c,d);
t1.truck_load();
}
}
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧
新聞標(biāo)題:學(xué)校信息系統(tǒng)、計算圖形面積、計算車重C++(繼承與派生)在線作業(yè)-創(chuàng)新互聯(lián)
轉(zhuǎn)載注明:http://www.rwnh.cn/article12/csjgdc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、網(wǎng)站內(nèi)鏈、自適應(yīng)網(wǎng)站、動態(tài)網(wǎng)站、外貿(mào)建站、商城網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)