
C++定义图书类,帮我改改
#include<iostream.h>classBook{charName,Author,Publisher;floatPrice;public:voidSetBook...
#include<iostream.h>
class Book
{ char Name,Author,Publisher;
float Price;
public:
void SetBook(char,char,char,float);
void Display();
};
void Book::Setbook(char a,char b,char c,float d)
{ Name=a;
Author=b;
Publisher=c;
Price=d;
}
void Book::Display()
{ cout<<"Name"<<'\t'<<"Author"<<'\t'<<"Publisher"<<'\t'<<"Price"<<'\n';
}
void main()
{ char x1,x2,x3;
float x4;
Book x;
cout<<"请输入书名、作者、出版社、单价";
cin>>x1>>x2>>x3>>x4;
x.SetBook(x1,x2,x3,x4);
x.Display();
} 展开
class Book
{ char Name,Author,Publisher;
float Price;
public:
void SetBook(char,char,char,float);
void Display();
};
void Book::Setbook(char a,char b,char c,float d)
{ Name=a;
Author=b;
Publisher=c;
Price=d;
}
void Book::Display()
{ cout<<"Name"<<'\t'<<"Author"<<'\t'<<"Publisher"<<'\t'<<"Price"<<'\n';
}
void main()
{ char x1,x2,x3;
float x4;
Book x;
cout<<"请输入书名、作者、出版社、单价";
cin>>x1>>x2>>x3>>x4;
x.SetBook(x1,x2,x3,x4);
x.Display();
} 展开
展开全部
char Name,Author,Publisher;不应该定义为char ,应该为字符串
cout<<"Name"<<'\t'<<"Author"<<'\t'<<"Publisher"<<'\t'<<"Price"<<'\n';
这里不应该为"Name"这样的形式,就Name就行
#include<iostream>
#include<string>
using namespace std;
class Book
{ string Name,Author,Publisher;
float Price;
public:
void SetBook(string ,string,string ,float );
void Display();
};
void Book::SetBook(string a,string b,string c,float d)
{ Name=a;
Author=b;
Publisher=c;
Price=d;
}
void Book::Display()
{ cout<<Name<<'\t'<<Author<<'\t'<<Publisher<<'\t'<<Price<<'\n';
}
void main()
{ string x1,x2,x3;
float x4;
Book x;
cout<<"请输入书名、作者、出版社、单价";
cin>>x1>>x2>>x3>>x4;
x.SetBook(x1,x2,x3,x4);
x.Display();
}
cout<<"Name"<<'\t'<<"Author"<<'\t'<<"Publisher"<<'\t'<<"Price"<<'\n';
这里不应该为"Name"这样的形式,就Name就行
#include<iostream>
#include<string>
using namespace std;
class Book
{ string Name,Author,Publisher;
float Price;
public:
void SetBook(string ,string,string ,float );
void Display();
};
void Book::SetBook(string a,string b,string c,float d)
{ Name=a;
Author=b;
Publisher=c;
Price=d;
}
void Book::Display()
{ cout<<Name<<'\t'<<Author<<'\t'<<Publisher<<'\t'<<Price<<'\n';
}
void main()
{ string x1,x2,x3;
float x4;
Book x;
cout<<"请输入书名、作者、出版社、单价";
cin>>x1>>x2>>x3>>x4;
x.SetBook(x1,x2,x3,x4);
x.Display();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询