Showing posts with label Structure. Show all posts
Showing posts with label Structure. Show all posts

Classes and Objects

Introduction
A class is a fundamental building block of the object oriented programming language C++. Bjarne Stroustup, the originator of C++ language, gave the name "C with classes" to this language initially. The class is the most important feature of C++. It implements OOP concepts and ties them together.
A class is a way to bind data (describing an entity) and its associated functions together. In C++, a class makes a data type that is used to create objects of this same type.
The prerequisites for classes and objects are structures and the functions. A structure provides a way to group data elements and a function organizes program actions into a named entity.
Class Specification
A class specification consists of two parts:
1. Class declaration
2. Class method definition
Declaration of a Class
A class is declared using the class keyword. the syntax of a class declaration is similar to that of a structure.
The general form of a class declaration is : LEARN MORE>>

Structures.....cont(1)

Initializing Structure Elements
The elements of a structure van be initialized either seperately using seperate assignment statements or jointly using the notation similar to that used for initializing arrays. The example given below demonstrates how structure elements can be initialized jointly or seperately.
struct student
{
int rollno;
char name[20];
short clas; // class is a reserved word of C++
float marks;
char grade;
} stud1, stud2;
LEARN MORE>>

Structures

A Structure is a collection of simple variables. The variables of a structure can be of different types: int, float and so on. (this is unlike the array, in which all the elements must be of the same type.) the data items or varible declared in the structure are called the members of the structure. The structure name is often reffered to as its tag.
For C++ programmers, structures are one of the two important building blocks in the understanding of objects and classes.
Defining a Structure
We know that structure is a collection of logically related variables referenced under a single name. These variables can be of different type, and each has a name which is used to select it from the structure.
A structure can be defined as a new named type, thus extending the number of avaialble types. LEARN MORE>>

Structure of a C++ Program

The structure of a C++ program is as described below:-
1. At the top of the program header files are declared.
2. A C++ prgram starts executing from main() function. The body of the main function is included with surly braces.
3. Each of the statment of the C++ program must end with a semicilon. a semicilon is also known as statement terminator.
So my first program would probably be:- LEARN MORE>>