📄 09p1.cpp
字号:
/*
NIIT 《C++ & CGI PROGRAMMING &SCRRIPTING》 Skill Base
教材P9.10 9.P.1
审核:周永 Laozhou@swpi.edu.cn 23:34 2004-10-18
测试环境:Microsoft Windowsn 2000(VC++);Red Hat Linux 7.3;Red Hat Linux 9.0
*/
//运行程序的时候,有意识的直接按回车键,有些项不输入
#include <iostream>
using namespace std;
class Customer
{
private:
char mobileNo[11];
char name[25];
char dateOfBirth[11];
char billingAddress[51];
char city[25];
char phoneNo[11];
float amountOutstanding;
void validate();
public:
Customer();
~Customer();
void print();
void get();
};
Customer::Customer()
{
*mobileNo = '\0';
*name = '\0';
*dateOfBirth = '\0';
*billingAddress = '\0';
*city = '\0';
*phoneNo = '\0';
amountOutstanding = 0.0f;
}
Customer::~Customer()
{
*mobileNo = '\0';
*name = '\0';
*dateOfBirth = '\0';
*billingAddress = '\0';
*city = '\0';
*phoneNo = '\0';
amountOutstanding = 0.0f;
}
void Customer::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 Customer::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;
validate();
}
void Customer::validate()
{
if(*mobileNo == '\0')
throw "The mobile number cannot be left blank";
if(*name == '\0')
throw "The name cannot be left blank";
if(*dateOfBirth == '\0')
throw "The date of birth cannot be left blank";
if(*billingAddress == '\0')
throw "The billing address cannot be left blank";
if(*city == '\0')
throw "The name of the city cannot be left blank";
if(*phoneNo == '\0')
throw "The phone number cannot be left blank";
if(amountOutstanding < 0)
throw "The outstanding amount cannot be less than zero";
}
int main()
{
Customer object;
try
{
object.get();
object.print();
}
catch(char *message)
{
cout << "Exception: " << message << endl;
}
catch(...)
{
cout <<"Unknown Exception!" <<endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -