2016-04-01 10 views
-1

ここに私のコードだと思う:次のコードの私は私のコードは完璧ですが、出力は適切ではありません

#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; 
} 

出力: 個人情報を入力します。

は、人の名前を入力します:スラジュ

生年月日を入力します。Varnam、/ 38、プネ

0123:1996年2月4日

は、アドレスを入力してください

は、携帯電話番号を入力します:8552004340

は、電子メールIDを入力します。 人が持っている任意の趣味を入力します:プロフェッショナルの情報を入力します。

は、会社の名前を入力します。 この会社で位置を入力します。 を入力してください経験年数:学術情報を入力します。

はもちろんの名前を入力します。 大学の名前を入力します。 passoutの年を入力します。 割合を入力します。 入力してください個人記録:人はに特化した被写体

1.Name:誕生スラジュ 2.Date:1996年2月4日 3.Address:Varnam、/ 38、プネ 4.Mobile番号: 2147483647 5.Eメールイド: 6.Hobby プロフェッショナルレコード:会社の

名前:この会社では 位置:長年の経験の 数:0

アカデミック詳細:の 名前コース:大学の3210名:passoutの 年:取得0 割合:0 人はに特化しています:

ここでの問題は、携帯電話番号を取った後、それは私に電子メールIDのプロンプトを与えないということですか他のフィールドの入力を取る。それだけで私に出力を与える。元の番号ではなく、ごみの値に変わります。私は入った。何が起こっているのか本当にわからない。誰か助けてもらえますか?

私はubuntuとC++シェルのオンラインでコードを実行しており、どちらも同じ結果を出すようです。

私はこの問題が何であるか分かりませんので、私はこの質問をしても怒らないでください!

+1

これは決して最小限のコードではありません。 – SergeyA

+0

複数のクラスを使用することをお勧めします。情報タイプごとに1つずつ。後で[友情と継承](http://www.cplusplus.com/doc/tutorial/inheritance/)について学ぶことができます。それはあなたにきれいなコードを与えるでしょう。私の$ 0。02 – Joel

+0

私は複数の継承を使用せず、3つのクラスをインスタンス化するように求めていますか?Joel – Suraj

答えて

3

あなたは32767 http://www.cplusplus.com/reference/climits/

8552004340の最大サイズが大きすぎる持つint型、などの携帯電話番号を格納しています!

文字列として保存する方がよい。

+0

intと同意します。 – Joel

+0

ravenspointようこそありがとうございます!サイズを忘れてしまいました。 – Suraj

+0

また、電話番号は先行ゼロを持つことができ、また国コードの+表記も可能です。 –

関連する問題