(a) 定义
Book
具有所有基本属性的类,例如标题、作者、出版商、价格等。定义默认构造函数display_data()
、用于显示Book
详细信息的成员函数。在此程序中使用适当的访问控制说明符。
输出:
Line 16: error: stray '\342' in program
compilation terminated due to -Wfatal-errors.
资源:
#include <iostream>
#include <string>
using namespace std;
Class Book
{
Int ISBNNo;
Char Title[30];
Char Author[30];
Char pub[50];
Float price;
Public: Book()
{
ISBNNO = 1001;
Strcpy(Title, ”C++ Programming”);
Strcpy(Author, “E.Balagurusamy”);
Strcpy(pub, “Tata Press”);
Price = 300;
}
Void display_data()
{
Cout << ”Book ISBNNO” << ISBNNO << endl;
Cout << ”Book Title” << Title << endl;
Cout << ”Book Author Name” << Author << endl;
Cout << ”Book Publisher” << pub << endl;
Cout << ”Book Price” << price << endl;
}
};
Main()
{
Book B;
B.display_data();
getch();
}