?? 10d1.cpp
字號:
/*
NIIT 《C++ & CGI PROGRAMMING &SCRRIPTING》 Skill Base
教材P10.8 10.D.1
審核:周永 Laozhou@swpi.edu.cn 23:59 2004-10-18
測試環境:Microsoft Windowsn 2000(VC++);Red Hat Linux 7.3;Red Hat Linux 9.0
*/
#include <iostream>
#include <string>
using namespace std;
class Person
{
protected:
string name;
string dateOfBirth;
string city;
string mobileNo;
string phoneNo;
public:
virtual void accept()
{
cout<< endl << "Name: ";
getline(cin,name);
cout << endl << "Date of Birth: ";
cin >> dateOfBirth;
cin.ignore();
cout << endl << "City: ";
getline(cin,city);
cout << endl << "Mobile phone number: ";
cin >> mobileNo;
cin.ignore();
cout << endl << "Residence phone number: ";
cin >> phoneNo;
cin.ignore();
}
virtual void display()
{
cout << endl << "Name : " << name;
cout << endl << "Date of birth : " << dateOfBirth;
cout << endl << "City : " << city;
cout << endl << "Mobile number : " << mobileNo;
cout << endl << "Residence number : " << phoneNo;
cin.ignore();
}
};
class Customer : public Person
{
private:
string billingAddress;
float amountOutstanding;
public:
virtual void accept()
{
cout << endl << endl << "ENTER CUSTOMER'S DETAILS";
Person::accept();
cout << endl << "Customer's billing address: ";
getline(cin, billingAddress);
cout << endl << "Amount due: ";
cin >> amountOutstanding;
}
virtual void display()
{
cout << endl << endl << "CUSTOMER'S DETAILS ";
Person::display();
cout << endl << "Billing address : " << billingAddress;
cout << endl << "Outstanding amount: " << amountOutstanding << endl;
}
};
class Dealer : public Person
{
private:
string shopAddress;
int numSold;
public:
virtual void accept()
{
cout << endl << endl << "ENTER DEALER'S DETAILS";
Person::accept();
cout << endl << "Shop address : ";
getline(cin, shopAddress);
cout << endl << "Number Sold : ";
cin >> numSold;
}
virtual void display()
{
cout << endl << endl << "DEALER'S DETAILS ";
Person::display();
cout << endl << "Shop address : "
<< shopAddress;
cout << endl << "Number sold : "
<< numSold << endl;
}
};
int main()
{
Person *ptr;
ptr = new Customer;
ptr->accept();
ptr->display();
ptr = new Dealer;
ptr->accept();
ptr->display();
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -