我是C ++的初学者,想要创建一个名为'Garment'的类,我在其中编码:
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
class Garments
{
char GCode[15];
char GType[15];
int GSize;
char GFabric[15];
float GPrice;
void Assign() {
if(strcmp(GFabric,"COTTON")==0) {
if(strcmp(GType,"TROUSER")==0)
GPrice=1300;
else if(strcmp(GType,"SHIRT")==0)
GPrice=1100;
} else {
if(strcmp(GType,"TROUSER")==0)
GPrice=1300-0.10*1300;
else if(strcmp(GType,"SHIRT")==0)
GPrice=1100-0.10*1100;
}
}
public:
Garments() {
strcpy(GCode,"NOT ALLOWED");
strcpy(GType,"NOT ALLOWED");
strcpy(GFabric,"NOT ALLOWED");
GSize=0;
GPrice=0;
}
void Input() {
cout<<"Enter Garment Code:";
cin>>GCode;
cout<<"\nEnter Garment Type(TROUSER/SHIRT)";
cin>>GType;
cout<<"\nEnter Garment Size:";
gets(GSize);
cout<<"\nEnter Garment Fabric:";
gets(GFabric);
Assign();
}
void Display() {
cout<<"Garment Code:"<<GCode;
cout<<"\nGarment Type:"<<GType;
cout<<"\nGarment Size:"<<GSize;
cout<<"\nGarment Fabric:"<GFabric;
cout<<"\nGarment Price:"<<GPrice;
}
};
void main()
{
clrscr();
Garments G;
G.Input();
G.Display();
getch();
}
上面的代码是否正确?在使用Turbo C ++编译时,我有两个错误:
int
转换为char*
。__s
时参数gets(char*)
中的类型不匹配。这两个错误都在gets(GSize);
行
如何纠正错误?