Electrofriends

C++ program using class to generate mark sheet using multiple inheritance

by Ranjith | April 4th, 2010.

Using multiple inheritances, prepare a Student Mark sheet, class marks for every student in three subjects. The inherited class generates mark sheet.

#include<iostream.h>
#include<stdio.h>
#include<dos.h>
class student
{
int roll;
char name[25];
char add [25];
char *city;
public: student()
{
cout<<"welcome in the student information system"<<endl;
}
void getdata()
{
cout<<"\n enter the student roll no.";
cin>>roll;
cout<<"\n enter the student name";
cin>>name;
cout<<\n enter ther student address";
cin>>add;
cout<<"\n enter the student city";
cin>>city;
}
void putdata()
{
cout<,"\n the [...]

Read More..

C++ class program to perform complex arithmetic using operator overloading

by Ranjith | April 4th, 2010.

Write a program to perform complex arithmetic using operator overloading

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
class complex
{
int real;
float image;
public:
void getdata()
{
cout<<"\n enter the real part of the complex";
cin>>real;
cout<<"\n enter the imaginary part of the complex";
cin>>image;
}
void operator + (complex);
void operator – (complex);
};
 
void complex :: operator + (complex c1)
{
complex temp;
temp.real=real+c1.real;
temp.image=image+c1.image;
if (temp.image>=0);
{
cout<<"\n complex no. after addition:";
cout<<temp.real<<"+"<<temp.image<<"i";
}
else
{
cout<<"\n complex no. after addition ";
cout<<temp.real<<temp.image<<"i";
}
}
void complex ::operator-(complex c1)
{
complex [...]

Read More..

C++ class program to perform rational number arithmetic

by Ranjith | April 4th, 2010.

Write a program to perform rational number arithmetic.

#include<stdio.h>
#include<iostream.h>
#include<conio.h>
class rational
{
int numer;
int denom;
public:
void getdata()
{
cout<<"\n enter the numerator part of the rational no.";
cin>>numer;
cout<<"\n enter the denominator part of the rational no.";
cin>>denom;
}
void operator+(rational);
void operator-(rational);
void operator *(rational);
void operator /(rational);
[...]

Read More..

C++ program using class to multiply by 10 to every member of a list

by Ranjith | April 4th, 2010.

Write a program using class which reads a list of N number of integer type in an array. It modifies the list by multiplying 10 to every number of the list. The modified list is displayed.

#include<iostream.h>
#include<conio.h>
class array
{
public: void readarray();
void multiply();
};
void array::readarray()
{
int a[10];
cout<<"Enter the elements of [...]

Read More..

C++ program to copy one file to anothere file

by Ranjith | March 13th, 2010.

AIM
A program to copy one file to another file and convert the lower case characters to upper case characters.
ALGORITHM
1) Start the process
2) Create the input file and out put file.
3) Get the input file name to fname1.
4) Get the output file name to fname2.
5) Open the infile(fanme1)
6) Check if infile.fail()
a) True:
i) Execute error conversion
ii) exit
7) open the outfile(fanme2)
check if outfile.fail()
a) repeat step(6:a)
9) check while [...]

Read More..

C++ class program to illestrate File operations

by Ranjith | March 13th, 2010.

AIM
Write a program to illustrate the write() member function which are usually used for transfer of data blocks to the file.
ALGORITHM
1. Start the process
2. Invoke the class
a. Create two inline member functions .ie, getdata() and dispdata()
i. getdata() for input
ii. dispdata() for display
3. Open the file in fstream mode
4. Write the data in to the file
5. Slose the file
6. Stop the process
PROGRAM

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class student
{
private:
int rno;
char name[10];
float [...]

Read More..

C++ program to implement Pure Virtual Functions

by Ranjith | March 13th, 2010.

AIM
A program to demonstrate how a pure virtual function is defined, declared and invoked from the object of derived class through the pointer of the base class.
ALGORITHM
1. Start the process
2. Invoke the class with pointer
3. Assign ptrgetdata()
a. Get the roll no and name of the student
5. Call the ptr->display()
a. Print the roll no and name
6. Stop the process
PROGRAM

#include<iostream.h>
#include<conio.h>
 
class base
{
private: int [...]

Read More..

C++ program to illestrate virtual functions

by Ranjith | March 13th, 2010.

AIM
A program to access the member of the derived class objects through an array of members. In this program, both the base class and the derived class member functions are preceded by the keyword
ALGORITHM
1. Start the process
2. Invoke the class with pointer
3. Assign ptr[0]

Read More..

C++ program to illustrate the static member function

by Ranjith | March 13th, 2010.

AIM
Write a program to illustrate the static member function.
ALGORITHM
1. Start the process
2. Invoke the class
i. Set the data member and member function as a static
b. Create two objects t1 and t2
3. Call the function t1.setcode
i. Increment the value of data member count
4. Call the function t1.setcode
i. Increment the value of data member count
5. Call the static member function showcount()
i. Display the value of count
6. Create a [...]

Read More..

C++ program to illustrate Hybrid Inheritance.

by Ranjith | March 13th, 2010.

C++ program to illustrate Hybrid Inheritance.

#include<iostream.h>
#include<conio.h>
class stu
{
protected:
int rno;
public:
void get_no(int a)
{
rno=a;
}
void put_no(void)
{
out<<"Roll no"<<rno<<"\n";
}
};
class test:public stu
{
protected:
float part1,part2;
public:
void get_mark(float x,float y)
{
part1=x;
part2=y;
}
void put_marks()
{
cout<<"Marks obtained:"<<"part1="<<part1<<"\n"<<"part2="<<part2<<"\n";
}
};
class sports
{
protected:
float score;
public:
void getscore(float s)
{
score=s;
}
void [...]

Read More..

Share and enjoy

    • Digg
    • Facebook
    • Technorati
    • StumbleUpon
    • Twitter
    • Reddit
    • del.icio.us
    • Yahoo! Buzz
Copyright©2009 www.electrofriends.com All Rights Reserved. Powered by Dhyeya