You are on page 1of 8

ASSIGNMENT-1 CSE202

Name

RUBIN D1911 A19

Section : Roll no :

Sol 1:C++ is a object oriented programming language. C++ is a more powerfull language. It is an extension of c with a class construct features. C++ is an incrementdiversion of c. Almost all c programs are also c++ programs. Like c the c++ program is a collection of function the main() function from where the execution of program started. Every c++ program must have the main(). C++ is a free form language with a few exceptions the compiler ignores carriage return and white spaces. C++ statement is also terminate with semicolons. Comment:- c++ introduces a new comment symbol. Comment start with a double slash symbol and terminate at the end of the line is ignored. Multi line comments can be written as://this is an example of // c++ program illustrate // some of its features. The c++ comment symbol /*.*/. /* this is an exm. Of c++ program to illustrate some of its features. We used cout and cin features for input &output purpose. We use iostream file as the header file. It contain the function prototypes for the standard input &out put function. C++ language is better than c language. C++ allows the programmer to more easily manage and operate with objects using an object oriented programing concepts. The c language cannot provide data hiding but the c++ language provides us the data hiding. So these no security in c than c++. The programs become short in c++. If follow top to down apporch. Data move openly from function to function. Function can transfer data from one from to another form. So the c++ is better than c language.

Sol 2:Inline function is a function which is expanded in a line when it is invoked. That is, the compiler replaces the function call with the corresponding function code. One of the objective of using function is to save memory space, which become appreciable when a function is called many times. Syntax:Inline function-header {

function } Eg:inline double cube(double) { return (a*a*a); }

Function Overloading:-it is a type of polymorphism. It means that we can design a family of function with one function name but different argument list or no. of arguments or different sequence of arguments. The function would perform different operation depending upon the argument list in the function call. Eg:// Function volume() is overloaded three times #include<iosteram.h> Using name space std; //declareations(prototype) int volume(int); double volume(double, int); long volume(long, int, int); int main() { cout<<volume(10)<<\n; cout<<volume(2.5,8)<<\n; cout<<volume(100,75,15)<<\n; return 0; } int volume(int s) //cube

{ return(s*s*s); } double volume(double r, int h) // cylinder { return(3.14*r*r*h); } long volume(long l, int b, int h); //for rectangular box { return(l*b*h); } output:1000 157.26 112500

Sol 3:Class specification has two parts : Class declaration Class function definition

T he class declaration describe the type and scope of its members. The class function definition describes how the class functions are implemented. Eg:class abc { private: variable declarations;

function declarations; public: variable declarations; function declarations; };

Sol 4:Private :- A section function can only be called by another function that is a member of its class. By default, all tha members of a class are private. Such a class is hidden from the world and do not serve any purpose. Syntax:class abc { private: variable declaration; function declarations; };

Public :- a public function can be accessed by a function outside class by the help of an object. Usually, all the functions are to be declared as public. Syntax:class abc { variable declaration; function declaration; }

Protected:It can only be called by another function that is the member of the class like private. But it can be inherited too.

Sol 5:Private :- A section function can only be called by another function that is a member of its class. By default, all tha members of a class are private. Such a class is hidden from the world and do not serve any purpose. Public :- a public function can be accessed by a function outside class by the help of an object. Usually, all the functions are to be declared as public. Class sample { int m; void read(void); //private member function public: void update(void); void write(void); }; If S1 is an object of sample, then S1.read(); //wont work as object can not be accessed as it is a private member(by default).

However the function read() can be called by the function update() to update the value of m. void sample :: update(void) { read(); //sample call in which no object is used.

Sol 6:#include<iostream.h> #include<conio.h> class book

{ public: int acc_no; char title[20], author[20], publisher[20]; public; void int(); void display(); }; void book :: int() { cout<<\n Enter accession Number:- ; cin>>acc_no; cout<<\n Enter title of the book:- ; cin>>title; cout<<\n Enter the author:-; cin>>author; cout<<Enter the publisher:-; cin>>publisher; } void book :: display() { int(); cout<<\n Accession Number is:-<<acc_no; cout<<\n The title of the book is:-<<title; cout<<\n Author is:-<<author; cout<<\n Publisher is :-<<publisher; }

void main() { book b; b.display(); getch(); }

Sol 8:Objects:- These are basic entities in an object oriented system. They may represent an account, name, place orany other item which a program has to handle. Eg:void main() { item a,b,c; } Class:- It is the way to bind the data and its members(or associated functions) together.It allows data and functions to be hidden from the world. Eg:class item { int number; float money; public: void getdata(int a, float b); void put data(void); };