第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

想用C++寫一個程序,求問有了解的嗎?

想用C++寫一個程序,求問有了解的嗎?

猛跑小豬 2021-11-24 21:11:29
設(shè)計一個father類,一個mother類和一個child類。期中child類繼承father類和mother類。father類和mother類都包含姓和名兩個數(shù)據(jù)成員,child類僅包含名數(shù)據(jù)成員。要求一個child類的對象能夠輸出其父,其母和自己的姓名。
查看完整描述

2 回答

?
慕的地8271018

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個贊

#include <string>
#include <iostream>

using namespace std;

//class father;
//class mother;
//class child;

class father
{
public:
father()//構(gòu)造函數(shù)
{
firstname="f";
lastname="F";
}
~father()//析構(gòu)函數(shù)
{
firstname.~string();
lastname.~string();
}
father(const string first,const string last)//帶參數(shù)的構(gòu)造函數(shù)
{
}
string getFirst()//取出father的名
{
return firstname;//="f";
}
string getLast()//取出father的姓
{
return lastname;//="F";
}
private:
string firstname;//名
string lastname;//姓
};//此處一定要有分號

class mother
{
public:
mother()//mother的構(gòu)造函數(shù)
{
firstname="m";
lastname="M";
}
~mother()//析構(gòu)
{
firstname.~string();
lastname.~string();
}
string getFirst()//取出mother的名
{
return firstname;//="m";
}
string getLast()//取出mother的姓
{
return lastname;//="M";
}
private:
string firstname;
string lastname;
};

class child:public father,public mother
{
public:
child(){ firstname="c"; }
~child(){ firstname.~string(); }
void showFa()
{
cout<<"Father's name is:";
cout<<father::getFirst()<<father::getLast()<<endl;
}
void showMo()
{
cout<<"Mother's name is:";
cout<<mother::getFirst()<<mother::getLast()<<endl;
}
void showCh()
{

cout<<"Child's name is:";
cout<<firstname<<father::getLast()<<endl;//子隨父姓
}
private:
string firstname;
};

int main(int argc, char* argv[])
{
child ch;
ch.showFa();
ch.showMo();
ch.showCh();
return 0;
}

出以下錯誤的話在首行加#include "stdafx.h"
e:\workspace\vc\baidu2\baidu2.cpp(102) : fatal error C1010: unexpected end of file while looking for precompiled header directive



查看完整回答
反對 回復(fù) 2021-11-28
?
三國紛爭

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超7個贊

#include <iostream.h>
#include<string.h>
class father{
char firstname[10];
char lastname[10];
public:
void print()
{
cout<<"父親的姓是:"<<firstname<<endl;
cout<<"父親的姓是:"<<lastname<<endl;
}
father()
{
strcpy(firstname,"佐");
strcpy(lastname,"助");
}

};
class mather{
char firstname[10];
char lastname[10];
public:
void print()
{
cout<<"母親的姓是:"<<firstname<<endl;
cout<<"母親的姓是:"<<lastname<<endl;
}
mather()
{
strcpy(firstname,"小");
strcpy(lastname,"櫻");
}
};
class child:public father,mather{
char lastname[10];
public:
void print()
{
father::print();
mather::print();
cout<<"小孩的名是:"<<lastname<<endl;
}
child()
{strcpy(lastname,"宇智波");}
};
int main()
{
child Child;
Child.print();
return 0;
}



查看完整回答
反對 回復(fù) 2021-11-28
  • 2 回答
  • 0 關(guān)注
  • 353 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號