⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 10d1.cpp

📁 C++ interview materials. Very helpful for interview. Including Answer.
💻 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 + -