C++ program – Classes with constant data members

0
723

C++ program – Classes with constant data members

CONSTRUCTION:

  1. Start the program.
  2. Include the header files.
  3. Define the constant value of n=5 using constant key word.
  4. Create the class student with member function avg mark.
  5. Access the member function using object in main function.
  6. Inside member function get input for all subject and calculate total, avg mark.
  7. Print total, average.
  8. Stop the program.

PROGRAM:

#include<iostream.h>
#include<conio.h>
const int n=5;
class student
{
public:
void avgmark()
{
int tam,eng,mat,sci,ss,tot;
float avg;
cout<<"Enter tamil marks";
cin>>tam;
cout<<"\nEnter english marks";
cin>>eng;
cout<<"\nEnter maths marks";
cin>>mat;
cout<<"\nEnter science marks";
cin>>sci;
cout<<"\nEnter ss marks";
cin>>ss;
tot=tam+eng+mat+sci+ss;
cout<<"total marks="<<tot<<"\n";
avg=float((tot)/n);
cout<<"avg mark="<<avg<<"\n";
}};
void main()
{
clrscr();
student s1;
s1.avgmark();
getch();
}

Leave a Reply