Advertisements
Advertisements
प्रश्न
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.
कोड लेखन
उत्तर
#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
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?