Advertisements
Advertisements
Question
Write a program in C++ to create a class test having member functions getmarks () to read marks of two subjects and showsum () to display the total marks.
Code Writing
Solution
#include<iostream.h>
#include<conio.h>
class test
{
int maths, science;
public:
void getmarks ();
void showsum ();
};
void test :: getmarks ()
{
cout<<"Enter marks in Maths and Science:";
cin>>maths>>science;
}
void test :: showsum ()
{
Cout<<,"Total="<<maths + science;
}
void main ()
{
test t;
t.getmarks ();
t.showsum ();
getch ();
}
shaalaa.com
Is there an error in this question or solution?