Answer to Question #77743 in C++ for Ravi

Question #77743
(a) A class "Student" has three data members: student_name, enrolment_no, marks of 5 subjects
and member function to assign streams on the basis of the criteria given below: 6
Average Marks Stream
>90% Computer Science
> 80 - 90% Science
>75 - 80% Commerce
>70 - 75% Arts
Below 70% Vocational
Write a C++ program to calculate average marks of each student and display student name,
enrolment no, and their stream.
1
Expert's answer
2018-06-01T04:56:45-0400
/// main.cpp
#include "Student.h"

#include <iostream>
#include <string>

int main()
{
std::string name;
unsigned num;
unsigned marks[MARKS_NUM];
std::cout << "Prompt a student name: ";
std::cin >> name;
std::cout << "Prompt a student enrolment no: ";
std::cin >> num;
std::cout << "Prompt a student 5 marks: ";
for (unsigned i = 0; i < MARKS_NUM; i++)
std::cin >> marks[i];

Student student(name, num, marks);
student.assign();

student.print();


return 0;
}
//================== Student.cpp
#include "Student.h"
#include <iostream>


Student::Student(const std::string& student_name, unsigned enrolment_no, unsigned marks[MARKS_NUM])
: student_name(student_name)
, enrolment_no(enrolment_no)
{
for (unsigned i = 0; i < MARKS_NUM; i++)
this->marks[i] = marks[i];
}

void Student::assign()
{
float avg = 0;

for (unsigned i = 0; i < MARKS_NUM; i++)
{
avg += marks[i];
}

avg /= MARKS_NUM;

if (avg > 90) stream = "Computer Science";
else if (avg > 80) stream = "Science";
else if (avg > 75) stream = "Commerce";
else if (avg > 70) stream = "Arts";
else stream = "Vocational";
}

void Student::print() const
{
std::cout << "Name: " << student_name << " Enrolment #" << enrolment_no << " Stream: " << stream << std::endl;
}
///============================ Student.h

#ifndef STUDENT_H_
#define STUDENT_H_

#include <string>

#define MARKS_NUM 5

class Student
{
public:
Student(const std::string& student_name, unsigned enrolment_no, unsigned marks[MARKS_NUM]);
void assign();
void print() const;
private:
std::string student_name;
unsigned enrolment_no;
unsigned marks[MARKS_NUM];
std::string stream;
};

#endif /* STUDENT_H_ */

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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS