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

📄 08d1.cpp

📁 C++ interview materials. Very helpful for interview. Including Answer.
💻 CPP
字号:
/*
NIIT 《C++ & CGI PROGRAMMING &SCRRIPTING》 Skill Base
教材P8.10	8.D.1
审核:周永 Laozhou@swpi.edu.cn	23:56 2004-10-18
测试环境:Microsoft Windowsn 2000(VC++);Red Hat Linux 7.3;Red Hat Linux 9.0
*/

#include <iostream>
#include <fstream>
using namespace std;
class Customer
{
private:
	char mobileNo[11];
	char name[25];
	char dateOfBirth[9];
	char billingAddress[51];
	char city[25];
	char phoneNo[11];
	float amountOutstanding;
public:
	void print()
	{
		cout << endl << "Mobile phone number: ";
		cout << mobileNo << endl;
		cout << "Name: ";
		cout << name << endl;
		cout << "Date of Birth: ";
		cout << dateOfBirth<<endl;	
		cout << "Customer's billing address: ";
		cout << billingAddress<<endl;
		cout << "City: ";
		cout << city << endl;
		cout << "Residence phone number: ";
		cout << phoneNo << endl;
		cout << "Amount due: ";
		cout << amountOutstanding << endl;
	}
	void get()
	{
		cout << "Mobile phone number: ";
		cin >> mobileNo;
		cin.ignore();
		cout << endl << "Name: ";
		cin.getline(name,25);
		cout << endl << "Date of Birth: ";
		cin >> dateOfBirth;
		cin.ignore();
		cout << endl << "Customer's billing address: ";
		cin.getline(billingAddress,51);
		cout << endl << "City: ";
		cin.getline(city,25);
		cout << endl << "Residence phone number: ";
		cin >> phoneNo;
		cout << endl << "Amount due: ";
		cin >> amountOutstanding;
	}
};

int main()
{
	Customer object;
	fstream file; 
	char reply = 'Y';
	file.open("customer.dat",ios::out|ios::app);
	while(reply == 'Y' || reply == 'y') 
	{
	cout << "Enter customer details " << endl;
	object.get();
	file.write((char *)&object,sizeof(object)); 
	cout << "Do you wish to continue ?[Y/N]";
	cin >> reply;
	}
	file.close(); 

	file.open("customer.dat",ios::in);
	file.read((char *)&object, sizeof(object));
	 object.print();
        while(file.eof() ==0) //Read Till The End Of The File
      {
             object.print();
             file.read((char *)&object, sizeof(object));
      }	
	file.close();
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -