Answer to Question #173487 in C++ for praveenkumar.b

Question #173487

Define a class Student with the following specification:

PRIVATE DATA MEMBERS:

regno integer sname 20 character s1, s2. s3 float total float

PUBLIC MEMBER FUNCTIONS:

Student() Default constructor to initialize data members, s1 = s2 = s3 = 0

Student(rn, sn, m, p, c) Parameterized constructor accept values for regno, sname, s1, s2 and s3

calculate() Function to calculate the student total marks

putdata() Function to display all the data members of student

~student() Destructor to destroy the data objects


1
Expert's answer
2021-03-26T07:51:45-0400
#include <iostream>
#include <string>
#include <iomanip>
 
using namespace std;
 
class Student
{
public:
               // Default constructor
  Student() {
      s1 = 0;
      s2 = 0;
      s3 = 0;
  } 
	// Parameterized constructor
  Student(int no, string name, float m, float p, float c) {
      regono = no;
      sname = name;
      s1 = m;
      s2 = p;
      s3 = c; 
  } 
	// Member functions
  float calculate(){
      total = s1 + s2 + s3;
       return total;
  }
  void putData();
	// destructor. 
  ~Student() {};
 
private:
               int regono;
               string sname;
               float s1;
               float s2;
               float s3;
               float total;
};
 
void Student::putData() {
  cout << "Student number: " << regono << endl;
  cout << "Student name:  " << sname << endl<<endl;
  cout << "s1 mathe:    " <<setw(6)<< fixed << setprecision(2) << s1 << endl;
  cout << "s2 physics:  " <<setw(6)<< fixed << setprecision(2) <<s2 << endl;
  cout << "s3 chemistry: " <<setw(6)<< fixed << setprecision(2) <<s3 << endl;
  cout << "total:       " <<setw(6)<< fixed << setprecision(2) <<calculate() << endl;
  cout << "==============================="<<endl;
}
 
int main() {
  Student st1(123, "Anna Kern", 80.25, 50, 90.45); //Parameterized constructor
  st1.putData();
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
30.04.21, 12:57

Dear Praveen Kumar b, please post new questions

Praveen Kumar b
30.04.21, 09:11

The list of random numbers stored in an integer and float array. Perform search operation to find the search number is present or not from an array using templates concept. * Print - Element Found or Element Not Found

Praveen Kumar b
30.04.21, 09:10

Create a class movie for ticket booking with data members theatrename, date, moviename, screenno, amount, no_of_tickets and total_amount and include functions reservation() , bookiing_details(). Create dynamic object and display ticket booking details.

Praveen Kumar b
30.04.21, 09:08

Create a class Index which keeps track of the Index value. Include member function GetIndex() to read index value.Write an overloaded function to display the greater index using > operator overloading.

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS