Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 26th, 2011, 03:55 AM
Registered User
 
Join Date: Apr 2011
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
Default c++ programming

how can i use classes in c++?
Reply With Quote
  #2 (permalink)  
Old October 10th, 2011, 08:30 AM
alexa007
Guest
 
Posts: n/a
Default

A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions. An object is an instantiation of a class. In terms of variables, a class would be the type, and an object would be the variable.

Classes are generally declared using the keyword class, with the following format:

class class_name {
access_specifier_1:
member1;
access_specifier_2:
member2;
...
} object_names;


Where class_name is a valid identifier for the class, object_names is an optional list of names for objects of this class. The body of the declaration can contain members, that can be either data or function declarations, and optionally access specifiers.
______________
SAP ERP
Reply With Quote
  #3 (permalink)  
Old October 11th, 2011, 01:37 AM
Registered User
 
Join Date: Sep 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Smile

Code:
class student
{
private:
	int admno;
	float eng,math,science;
	float total;
	float ctotal()
	{
		return eng+math+science;
	}
public:
	void Takedata()
	{
		cout<<"Enter admission number ";
		cin>> admno;
		cout<< "Enter marks in english, math, science ";
		cin>>eng>>math>>science;
		total=ctotal();
	}

	void Showdata()
	{
		cout<<"Admission number "<<admno<<"\nEnglish "
			<<eng<<"\nMath "<<math<<"\nScience "<<science<<"\nTotal "<<total;
	}
};

int main ()
{
	student obj ;
	obj.Takedata();
	obj.Showdata();
	getch();
	return 0;
}


http://www.cppforschool.com
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Do u know PHP Programming is Most Used Programming Language annaawills Beginning PHP 5 March 8th, 2010 09:48 AM
device DLL programming in client side programming hendyhanusin ASP.NET 1.0 and 1.1 Professional 2 February 19th, 2009 12:01 PM
device DLL programming in client side programming hendyhanusin ASP.NET 1.0 and 1.1 Basics 0 March 21st, 2007 08:05 AM
device DLL programming in client side programming hendyhanusin ASP.NET 2.0 Professional 1 March 21st, 2007 08:04 AM
Qt programming, bugs in first programming sateeshgalla BOOK Beginning Linux Programming, 3rd Edition 0 October 14th, 2005 08:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.