(1), download Visual Studio 2010
(2), create the project
(3), create header file
(4), creating a resource file
(5), CGoods.h documents
Class Cgoods
{
private:
char name[21];//name
int Amount; Quantity
float price; Price
float Total_value;//Total Value public
:
cgoods (void);
~cgoods (void);
void Registergoods (char*,int,float); Register the new Commodity
void counttotal (void);//Calculate the total value of the commodity
char* GetName ()//Read the commodity name
int getamount (void);//Read the number
of items float getprice (void); Read the commodity unit price
float gettotal_value (void);//Read the total value of the goods
};
(6), CGoods.cpp documents
#include <iostream>//io streaming file Introduction #include "CGoods.h"//header file introduced into/*************************************************** /Cgoods::cgoods (void) {}/********************************* ///////////////////////////
/void Cgoods::registergoods (char* name,int number,float price) {
strcpy (Name,name);
This->amount = number;
This->price = Price; }/************************************************************************//* Get product Name * */************************************************************************/char* CGo
Ods::getname () {return Name;} /*****************************************************//////* Get the quantity of goods/*/*******************
/int Cgoods::getamount (void) {return Amount;} /************************************************************************//* Get commodity price * */************************************************************************/float cgoods:
: GetPrice () {return price;} /************************************************************************//* Calculate total value of goods * */************************************************************************/void Cgoods:
: Counttotal () {total_value = Price * AMOUNT;} /************************************************************************///* Total value of goods acquired */
/*********************************************/float Cgoods::gettotal_value () {return total_value;} /************************************************************************///* destructor method * */************************************************************************/Cgoods::~cgoods
(void) {}/************************************************************************//* Keynote method *//************************************************************************/int main (
void) {using namespace std;
Cgoods Cgoods; Registered commodity Cgoods.
Registergoods ("Apple", 4,3.7); Calculates the total price cgoods.
Counttotal (); Cout<<cgoods.
Gettotal_value () << "\ n"; }