C++ Program to Read a Set of Lines

This is a program to read a set of lines and find out the number of characters, word and lines in a given text and display each word of the text in different lines. #include<iostream.h> #include<conio.h> Void main () { Int i=0, linecount=1, wordcount=1; Char str [100]; Clrscr (); Cout<<”\n Enter the lines”; Cin.get (str, 100, ‘#’); Do { If (str[i] ==’’ ?? str [i] ==’\n’) { Wordcount++; } If (str[i] ==’\n’) { Linecount++; } I++; } While (str[i]! = ‘\o’); Cout<<”\n the number of characters...

read more

C++ program using multiple inheritance

This program consists of two base classes and one derived class. The base class “Stuinfo” contains the data members: name, roll. And another base class “Stuacademic info” contains the data members: course and semester. The derived class “stuaddressinfo” contains the data members: address only. #include<iostream.h> #include<conio.h> Class Stuinfo { Private: Char name [25]; Int roll; Public: Void getdata () { Cout<<”\n Enter name”; Cin>>name; Cout<<”\n Enter roll”; Cin>> roll; } Void...

read more

C++ Program to add two complex number

Operator overloading is the process by which pre-defined symbols like “+”, “-”, “<=” gets additional meaning. This program is  used to add two complex number using operator overloading. #include<iostream.h> #include<conio.h< Class sample { Private: Int x, y; Public: Void getdata () { Cout<<”\n Enter value of x and y of complex number”; Cin>>x>>y; } Sample operator + (sample obj) { Obj.y = x+obj.x; Obj.y =y +obj.y; Return (obj); } Void display () { Cout<<”\n...

read more

C++ Program to Find Interest

Constructor can be defined as the member function, which has the same name of the class. the object created by the constructor is destroyed with the help of destructor. This is a program to find the interest using constructor. #include<iostream.h> #include<conio.h> Class interest { Private: Float principle, time, rate, interest; Public: Interest (); Interest (float, float, float); Void display (); }; Interest:: interest () { Interest =0; Principle = 0; Time=0; Rate=0; } Interest:: Interests (float p, float t, float...

read more

C++ Program using If-else Statement

This program shows the simple use of if-else statement. In this condition, if one statement goes wrong, other condition is applied. This is a program to find a leap year. #include<iostream.h> #include<conio.h> Void main () { Int year; Clrscr (); Cout<<”\n enter year (in 4- digits)”; Cin>>year; If (year % 100==0) { If (year % 400 == 0) Cout<<”\n leap year”; Else Cout<<”\n not a leap year”; } Else If (year % 4 ==0) Cout<<”\n leap year”; Else Cout<<”\n not a leap year”; getch...

read more

C++ program Showing multi-dimensional array

This program is an example for multi-dimensional array. Array can be defined as a group of similar objects, refrenced by the common name. This is a program to read sales of 10 districts in 12 months and calculate total sales of each district. #include<iostream.h> #include<conio.h> Void main () { Int district =10; Int month =12; Float sales [district] [month]; Int I, j; Float total; For (=0; i<10; i++) { Total=0; For (j=0; j<12; j++) { Cout<<”\n enter sales for district”<<i+1<<”for...

read more

C++ Program showing assignment operator overloading

The symbol ‘=’ is used as Assignment operators. It is used to assign a value of result for an expression. This is a sample program showing the overloading of  Assignment operators in c++. #include<iostream.h> #include<conio.h> Class sample { Private: Int x, y; Public: Void getdata () { Cout <<” \n enter the value of x and y”; Cin>> x>>y; } Void operator = (sample obj) { X= obj.x; Y= obj.y; } Void display () { Cout<<”\n value of x”<<x; Cout<<”\n value of...

read more

C++ Program showing constructor overloading

Constructor is a member function with the same name as of it’s class. This program is used to find the perimeter of square using constructor overloading. #include<iostream.h> #include<conio.h> Class perimeter { Int l, b, p; Public: Perimeter () { Cout<<”\n Enter the value of l and b”; Cin>>l>>b; } Perimeter (int a) { L=b=a; } Perimeter (int l1, int b1) { l=l1; b=b1; } Perimeter (perimeter and peri) { l= peri.l; b= peri.b; } Void calculate () { P = 2* (l +b) Cout <<p; } }; Void main () { Perimeter...

read more

C++ Program Using Friend Function

Friend function is used to access private, public and protected data’s of a class from outside of the class. In common the function that is not a member of the class cannot access the data’s of a class. This program can access the private data of a class by non-member function through friend where the friend function is declared in the location of public category. #include<iostream.h> #include<conio.h> Class sample { Private: Int x; Public: Void getdata (0; Friend void display (class sample); }; Void sample:: getdata...

read more

C++ Program Using Structure

A structure can be said as, the collection of  datas under a single name. This program is designed to read and display name, roll no, address and weight of a student by using structure. #include<iostream.h> #include<conio.h> Struct School { Int roll; Char name [25]; Char address [25]; Float weight; } stu; Void main () { Cout<<”\n enter the roll no”; Cin>>stu.roll; Cout<<”\n enter name”; Cin>>stu.name; Cout<<”\n enter address”; Cin>>stu.address; Cout<<”\n ether...

read more
Page 1 of 812345...Last »