Getting Started with C + +-classes and objects

Source: Internet
Author: User
Tags visual studio 2010

(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"; }



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.