?? 對象.cpp
字號:
#include <iostream.h>
#include <iomanip.h>
#include <cstring.h>
class Cgoods
{
private:
char Name[21];
int Amount;
float Price;
float Total_value;
public:
void RegisterGoods(char[],int,float);
void CountTotal(void);
void GetName(char[]);
int GetAmount(void);
float GetPrice(void);
float GetTotal_value(void);
};
void CGoods::RegisterGoods(char name[],int amount,float price)
{
strcpy(Name,name);
Amount=amount;
Price=price;
}
void CGoods::CountTotal(void)
{
Total_value=Price*Amount;
}
void CGoods::GetName(char name[])
{
strcpy(name,Name);
}
int CGoods::GetAmount(void)
{
return(Amount);
}
float CGoods::GetPrice(void)
{
return(Price);
}
float CGoods::GetTotal_value(void)
{
return(Total_value);
}
int main()
{
CGoods car;
char str[21];
int number;
float pr;
cout<<"請輸入汽車型號";
cin.getline(str,20);
cout<<"請輸入汽車的數量:";
cin>>number;
cout<<"請輸入汽車的單價:";
cin>>pr;
car.RegisterGoods(str,number,pr);
car.CountTotal();
str[0]='\0';
car.GetName(str);
cout<<setw(20)<<str<<setw(5)<<car.GetAmount();
cout<<setw(10)<<car.GetPrice()<<setw(20)<<car.GetTotal_value()<<endl;
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -