用成员函数和存储值定义 book class
define book class with member function and store value
有人可以帮我满足以下要求
Class 包含属性 BookId、BookName 和 Price 的图书。它还包含成员函数来输入和显示其属性。
写另一个class Writer 包含他写的WriterName, Address 和NumberofBooks 的属性。它包含书籍对象数组作为 iys 成员。数组的长度应该是5来存储五本书的数据。
它还应该包含一个成员函数来输入和显示它的属性。
I found a solution on google with below code 但它似乎对我一半的要求有用。
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class BOOK
{
int BOOKNO;
char BOOKTITLE[20];
float PRICE;
void TOTAL_COST(int N)
{
float tcost;
tcost=PRICE*N;
cout<<tcost;
}
public:
void INPUT()
{
cout<<"Enter Book Number ";
cin>>BOOKNO;
cout<<"Enter Book Title ";
gets(BOOKTITLE);
cout<<"Enter price per copy ";
cin>>PRICE;
}
void PURCHASE()
{
int n;
cout<<"Enter number of copies to purchase ";
cin>>n;
cout<<"Total cost is ";
TOTAL_COST(n);
}
};
void main()
{
BOOK obj;
obj.INPUT();
obj.PURCHASE();
getch();
}
要包含一个对象的实例,您需要在class中声明该类型的成员:
class Writer
{
const size_t MAX_BOOKS_WRITTEN = 5U;
Book books_written[MAX_BOOKS_WRITTEN];
};
在上面class,"that contains that contains"写了一个数组书。
有人可以帮我满足以下要求
Class 包含属性 BookId、BookName 和 Price 的图书。它还包含成员函数来输入和显示其属性。
写另一个class Writer 包含他写的WriterName, Address 和NumberofBooks 的属性。它包含书籍对象数组作为 iys 成员。数组的长度应该是5来存储五本书的数据。 它还应该包含一个成员函数来输入和显示它的属性。
I found a solution on google with below code 但它似乎对我一半的要求有用。
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class BOOK
{
int BOOKNO;
char BOOKTITLE[20];
float PRICE;
void TOTAL_COST(int N)
{
float tcost;
tcost=PRICE*N;
cout<<tcost;
}
public:
void INPUT()
{
cout<<"Enter Book Number ";
cin>>BOOKNO;
cout<<"Enter Book Title ";
gets(BOOKTITLE);
cout<<"Enter price per copy ";
cin>>PRICE;
}
void PURCHASE()
{
int n;
cout<<"Enter number of copies to purchase ";
cin>>n;
cout<<"Total cost is ";
TOTAL_COST(n);
}
};
void main()
{
BOOK obj;
obj.INPUT();
obj.PURCHASE();
getch();
}
要包含一个对象的实例,您需要在class中声明该类型的成员:
class Writer
{
const size_t MAX_BOOKS_WRITTEN = 5U;
Book books_written[MAX_BOOKS_WRITTEN];
};
在上面class,"that contains that contains"写了一个数组书。