Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 我认为我的代码是完美的,但输出不正确_C++_Oop - Fatal编程技术网

C++ 我认为我的代码是完美的,但输出不正确

C++ 我认为我的代码是完美的,但输出不正确,c++,oop,C++,Oop,这是我的密码: #include <iostream> #include <string> using namespace std; class Personal_Record { public: Personal_Record(); Personal_Record(string nam, string dob, string addr, int mobNum, string ema, string hob);

这是我的密码:

#include <iostream>
#include <string>

using namespace std;

class Personal_Record {

    public:
        Personal_Record();
        Personal_Record(string nam, string dob, string addr, int mobNum, string ema, string hob);
        void Get_PersonalRecord();
        void Display_PersonalRecord();

    protected:
        string name;
        string dateOfBirth;
        string address;
        int mobileNumber;
        string emailId;
        string hobby;

};

Personal_Record::Personal_Record() 
{
    name = "";
    dateOfBirth = "";
    address = "";
    hobby = "";
}

Personal_Record::Personal_Record(string nam, string dob, string addr, int mobNum, string ema, string hob)
{
    name = nam;
    dateOfBirth = dob;
    address = addr;
    mobileNumber = mobNum;
    emailId = ema;
    hobby = hob;
}


void Personal_Record::Get_PersonalRecord()
{
    cout << endl << "Enter the name of the person: ";
    cin >> name;
    cout << endl << "Enter the date of birth: ";
    cin >> dateOfBirth;
    cout << endl << "Enter the address: ";
    cin >> address;
    cout << endl << "Enter the mobile number: ";
    cin >> mobileNumber;
    cout << endl << "Enter the e-mail id: ";
    cin >> emailId;
    cout << endl << "Enter any hobby the person has: ";
    cin >> hobby;
}

void Personal_Record::Display_PersonalRecord()
{
    cout << "Personal Record:" << endl << endl;
    cout << "1.Name: " << name << endl;
    cout << "2.Date Of Birth: " << dateOfBirth << endl;
    cout << "3.Address: " << address << endl;
    cout << "4.Mobile Number: " << mobileNumber << endl;
    cout << "5.E-mail Id: " << emailId << endl;
    cout << "6.Hobby" << hobby << endl; 
}

class Professional_Record {

    public:
        Professional_Record();
        Professional_Record(string nameOfCom, string pos, int xp);
        void Get_Professional_Record();
        void Display_Professional_Record();

    protected:
        string nameOfCompany;
        string position;
        int experienceInYears;

};

Professional_Record::Professional_Record()
{
    nameOfCompany = "";
    position = "";
    experienceInYears = 0;
}

Professional_Record::Professional_Record(string nameOfCom, string pos, int xp)
{
    nameOfCompany = nameOfCom;
    position = pos;
    experienceInYears = xp;
}

void Professional_Record::Get_Professional_Record()
{
    cout << endl << "Enter name of the company: ";
    cin >> nameOfCompany;
    cout << endl << "Enter position in this company: ";
    cin >> position;
    cout << endl << "Enter number of years of experience: ";
    cin >> experienceInYears;
}


void Professional_Record::Display_Professional_Record()
{
    cout << "Professional Record: " << endl << endl;
    cout << "Name of the Company: " << nameOfCompany << endl;
    cout << "Position in this company: " << position << endl;
    cout << "Number of years of experience: " << experienceInYears << endl; 
}

class Academic_Record {

    public:
        Academic_Record();
        Academic_Record(string nameOfCou, string nameOfCol, int passOut, float percent, string special);
        void Get_Academic_Record();
        void Display_Academic_Record();

    protected:
        string nameOfCourse;
        string nameOfCollege;
        int passOutYear;
        float percentage;
        string specialization;

};

Academic_Record::Academic_Record()
{
    nameOfCourse = "";
    nameOfCollege = "";
    passOutYear = 0;
    percentage = 0.0;
    specialization = "";
}

Academic_Record::Academic_Record(string nameOfCou, string nameOfCol, int passOut, float percent, string special)
{
    nameOfCourse = nameOfCou;
    nameOfCollege = nameOfCol;
    passOutYear = passOut;
    percentage = percent;
    specialization = special;
}

void Academic_Record::Get_Academic_Record()
{
    cout << endl << "Enter the name of the course: ";
    cin >> nameOfCourse;
    cout << endl << "Enter the name of the college: ";
    cin >> nameOfCollege;
    cout << endl << "Enter year of passout: ";
    cin >> passOutYear;
    cout << endl << "Enter the percentage: ";
    cin >> percentage;
    cout << endl << "Enter the subject the person has specialized in: ";
    cin >> specialization;
}

void Academic_Record::Display_Academic_Record()
{
    cout << endl << "Academic Details:" << endl;
    cout << "Name of the Course: " << nameOfCourse << endl;
    cout << "Name of the College: " <<  nameOfCollege << endl;
    cout << "Year of passout: " <<  passOutYear << endl;
    cout << "Percentage acquired: " << percentage << endl;
    cout << "The person has specialized in: " << specialization << endl;
}

class Bio_Data : public Personal_Record, public Professional_Record, public Academic_Record {

    public:
        void Display_BioData();

};

void Bio_Data::Display_BioData()
{
    Display_PersonalRecord();
    Display_Professional_Record();
    Display_Academic_Record();
}

int main()
{
    Bio_Data bd;
    cout << "Enter Personal Information: " << endl << endl;
    bd.Get_PersonalRecord();
    cout << "Enter Professional Information: " << endl << endl;
    bd.Get_Professional_Record();
    cout << "Enter Academic Information: " << endl << endl;
    bd.Get_Academic_Record();
    bd.Display_BioData();
    return 0;
}
#包括
#包括
使用名称空间std;
班级个人档案{
公众:
个人记录();
个人记录(字符串nam、字符串dob、字符串addr、int mobNum、字符串ema、字符串hob);
void Get_PersonalRecord();
void Display_PersonalRecord();
受保护的:
字符串名;
出生日期字符串;
字符串地址;
国际移动电话;
字符串emailId;
弦乐爱好;
};
个人记录::个人记录()
{
name=“”;
出生日期=”;
地址=”;
爱好=”;
}
Personal_Record::Personal_Record(字符串nam、字符串dob、字符串addr、int mobNum、字符串ema、字符串hob)
{
姓名=不结盟运动;
出生日期=出生日期;
地址=地址;
mobileNumber=mobNum;
emailId=ema;
爱好=滚刀;
}
作废个人记录::获取个人记录()
{
姓名;
无法确定出生日期;
cout地址;
移动电话;
cout-emailId;
爱好;
}
作废个人记录::显示个人记录()
{

cout您正在将手机号码存储为int,最大大小为32767

8552004340太大了


最好将其存储为字符串。

这不是以任何方式表示的最小代码。我建议您使用多个类。每个类对应一种信息类型。稍后,您可以了解。这将为您提供更清晰的代码。我的$0.02好吧,所以您要求我不要使用多重继承,而只是实例化3个类,对吗?JoeActual是另一种方式d:使用从基类派生的多重继承。同意int的说法。非常感谢RavenPoint!。我只是忘记了大小。电话号码可以有前导零,也可以有国家代码的+符号。我知道这是吹毛求疵,但是
int
的最大值必须至少达到32767。它可能要大得多ke在大多数32位和64位系统上。@NathanOliver重要的是,如果代码是在不同的平台上构建的,则不要有破坏的设计。C中的int保证容纳32767,而不是更多