A class student has three data members: name, roll, marks of 5 subjects and member functions to assign streamson the basis of the table given belowStreamAverage markscomputer science96% and more91%-95%86% 90%electronicsmechanical81% 85%76% 80%electricalchemical71% 75%civilDeclare the class student and define the member functions using oops in c++
Question
A class student has three data members: name, roll, marks of 5 subjects and member functions to assign streamson the basis of the table given belowStreamAverage markscomputer science96% and more91%-95%86% 90%electronicsmechanical81% 85%76% 80%electricalchemical71% 75%civilDeclare the class student and define the member functions using oops in c++
Solution
Here is a simple implementation of the Student class in C++:
#include<iostream>
#include<string>
using namespace std;
class Student {
string name;
int roll;
float marks[5];
public:
void setData(string n, int r, float m[5]) {
name = n;
roll = r;
for(int i=0; i<5; i++)
marks[i] = m[i];
}
string assignStream() {
float average = 0;
for(int i=0; i<5; i++)
average += marks[i];
average /= 5;
if(average >= 96)
return "Computer Science";
else if(average >= 91)
return "Computer Science";
else if(average >= 86)
return "Electronics";
else if(average >= 81)
return "Mechanical";
else if(average >= 76)
return "Electrical";
else if(average >= 71)
return "Chemical";
else
return "Civil";
}
void displayData() {
cout << "Name: " << name << endl;
cout << "Roll: " << roll << endl;
cout << "Stream: " << assignStream() << endl;
}
};
In this code, we have a class Student with data members name, roll, and marks (an array of 5 floats). The member function setData is used to set the data members. The assignStream function calculates the average of the marks and assigns a stream based on the average. The displayData function is used to display the student's data.
Similar Questions
Create a class VIT with data members student roll no, name, marks define a constructor to initilize the data members create a derived class student ,define a member function to calculate the average mark of the student
A hospital wants to create a database regarding its indoor patients. The information to store includes(a) Name of patient(b)Date of admission(c)Disease(d)Date of dischargeUse the Date class created in previous program to store the date. The patient class comprises of The memberfunctions to enter the information and display the list of all patients in database using oops in c++
You are developing a Student Record Management System in C. The system needs to store and manage information for multiple students, including their names, roll numbers, and marks obtained in different subjects. Implement array in structures to read, write, and compute average marks and the students scoring above and below the average marks for a class of N students. INPUT/OUTPUT EXAMPLE: Enter the number of students: 3 Enter details for 3 students: Student 1: Name: A Roll Number: 1 Marks in 5 subjects: Subject 1: 12 Subject 2: 13 Subject 3: 14 Subject 4: 15 Subject 5: 16 Student 2: Name: BB Roll Number: 2 Marks in 5 subjects: Subject 1: 11 Subject 2: 13 Subject 3: 12 Subject 4: 15 Subject 5: 14 Student 3: Name: CC Roll Number: 10 Marks in 5 subjects: Subject 1: 13 Subject 2: 14 Subject 3: 16 Subject 4: 17 Subject 5: 11 Class average marks: 13.73 Students scoring above average: A (Roll Number: 1) CC (Roll Number: 10) Students scoring below average: BB (Roll Number: 2)
We want to calculate the total marks of each student of a class in Physics,Chemistry and Mathematics and the average marks of the class. The number of students in the class are entered by the user. Create a class named Marks with data members for roll number, name and marks. Create three other classes inheriting the Marks class, namely Physics, Chemistry and Mathematics, which are used to define marks in individual subject of each student. Roll number of each student will be generated automatically using inheritance by c++
Define a class Student that keeps track of academ icr ecord of students in a school. The class should containthe follow ing data m em ber s:rollNum – Roll num ber of studentname – Nam e of studentmarksList – List of m arks in fiv e subjectsstream – A: Ar ts, C: Com m er ce, S: Sciencepercentage – Per centage com puted using m arksgrade – Grade in each subject com puted using m arksdivision – Div ision com puted on the basis of ov erallper centageThe class should suppor t the follow ing m ethods:1 . __init__ for initializing the data m em ber s.2 . setMarks to take m arks for fiv e subjects as aninput from the user .3 . getStream for accessing the str eam of thestudent.4 . percentage for com puting the ov erallper centage for the student.5 . gradeGen that generates grades for each studentin each cour se on the basis of the m arksobtained. Cr iter ia for com puting the grade is asfollow s:Marks Grade>= 90 A<90 and >=80 B<80 and >=65 C<65 and >=40 D<40 E6. division for computi ng di v i si on on the basi s of the fol l ow i ngc r iter i a based on ov er al l per centage of mar k s scor ed:Percentage Division>= 60 I<60 and >=50 II<50 and >=35 III7 . __str__ that di spl ay s student i nfor mati on.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.