📄 page10_17.cpp
字号:
/*
NIIT 《C++ & CGI PROGRAMMING &SCRRIPTING》 Skill Base
教材P10.17
审核:周永 Laozhou@swpi.edu.cn 23:36 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;
}
};
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 *personptr[100];
int i;
int choice = 0, ctr = 0;
while(choice != 4 && ctr < 100)
{
cout << endl << "CUSTOMER MENU" << endl;
cout << "1. Accept the details of a customer" << endl;
cout << "2. Accept the details of a dealer" << endl;
cout << "3. Display the details " << endl;
cout << "4. Quit the application" << endl;
cout << "Enter choice (1 - 4): ";
cin >> choice;
cin.ignore();
switch(choice)
{
case 1:
personptr[ctr] = new Customer;
personptr[ctr]->accept();
ctr++;
break;
case 2:
personptr[ctr] = new Dealer;
personptr[ctr]->accept();
ctr++;
break;
case 3:
for(i = 0; i < ctr; i++)
personptr[i]->display();
break;
case 4:
continue;
default:
cout << "Invalid option!Please enter 1 - 4 only" << endl;
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -