Header Ads

you have been given a task to develop a program in C++ that will take marks of different assessments as input and displays total marks as output

The Virtual University of Pakistan is an institute that offers technical and non-technical courses based on the distance learning model where one can join any of the courses just by using a computer system. Consider that you are enrolled in a course, OOP (Object Oriented Programming), and you have been given a task to develop a program in C++ that will take marks of different assessments as input and displays total marks as output.

Step by step instructions: 

  • Write a C++ class name Student with the following attribute: Student Id, Student name, quiz marks (for 4 quizzes), assignment marks (for 2 assignments), Mid Term Marks, Final Term Marks, Total Marks 
  • Write a parameterized constructor which passes all the data members of the Student class? 
  • Write an appropriate copy constructor for the student class 
  • Write member functions for the following requirements: 


Function Name Description
enterData() To input data from the user through the console as mentioned in the screenshot.
calculateResult() To calculate the result according to the grading scheme.
displayData() To print data on the screen as mentioned in the screenshot.

Grading scheme:


Activity Weightage Number of activities Formulation
Quiz 10% 4 Obtained Marks in all quizzes / Total Marks in all quizzes * 10
Assignment 20% 2 Obtained Marks in all Assignments/ Total Marks in all Assignments * 10
Mid Term Exam 30% 1 Obtained Marks in all Mid Term/ Total Marks in all Mid Term                       * 10
Final Term Exam 40% 1 Obtained Marks in all Final Term / Total Marks in all Final Term                      * 10

Perform the following tasks in main(): 
  • Create an array of size 3 Student objects using the new operator
  • Initialize the index [0] using parameterized constructor 
  • Enter data for the index [1] through enterData() 
  • Copy index[1] object into index [2] by using copy constructor 
  • Display all the Records by using displayData()

Program:


#include <iostream>
#include <string.h>
#include <conio.h>

using namespace std;

class Student
{
public:
Student() {}
Student(string Student_Id, string Student_name, int quiz_marks1, int quiz_marks2, int quiz_marks3, int quiz_marks4, int assignment_marks1, int assignment_marks2, int Mid_Term_Marks, int Final_Term_Marks);
string Student_name, Student_Id;
  float quiz_marks1, quiz_marks2, quiz_marks3, quiz_marks4, assignment_marks1, assignment_marks2, Mid_Term_Marks, Final_Term_Marks, Total_Marks, totalQuiz, TotalAssignment, TotalMidterm, TotalFinalterm;
public:

void enterData(string Student_Id, string Student_name, int quiz_marks1, int quiz_marks2, int quiz_marks3, int quiz_marks4, int assignment_marks1, int assignment_marks2, int Mid_Term_Marks, int Final_Term_Marks);

void calculateQuiz();
void calculateAssignment();
void calculateMidterm();
void calculateFinalterm();
void calculateTotalMarks();
void displayData();
Student(Student &obj)
{
this->Student_Id = obj.Student_Id;
this->Student_name = obj.Student_name;
this->quiz_marks1 = obj.quiz_marks1;
this->quiz_marks2 = obj.quiz_marks2;
this->quiz_marks3 = obj.quiz_marks3;
this->quiz_marks4 = obj.quiz_marks4;
this->assignment_marks1 = obj.assignment_marks1;
this->assignment_marks2 = obj.assignment_marks2;
this->Mid_Term_Marks = obj.Mid_Term_Marks;
this->Final_Term_Marks = obj.Final_Term_Marks;
}
};

Student::Student(string Student_Id, string Student_name, int quiz_marks1, int quiz_marks2, int quiz_marks3, int quiz_marks4, int assignment_marks1, int assignment_marks2, int Mid_Term_Marks, int Final_Term_Marks)
{
enterData(Student_Id, Student_name, quiz_marks1, quiz_marks2, quiz_marks3, quiz_marks4, assignment_marks1, assignment_marks2, Mid_Term_Marks, Final_Term_Marks);
}
void Student::enterData(string Student_Id, string Student_name, int quiz_marks1, int quiz_marks2, int quiz_marks3, int quiz_marks4, int assignment_marks1, int assignment_marks2, int Mid_Term_Marks, int Final_Term_Marks)
{
this->Student_Id = Student_Id;
this->Student_name = Student_name;
this->quiz_marks1 = quiz_marks1;
this->quiz_marks2 = quiz_marks2;
this->quiz_marks3 = quiz_marks3;
this->quiz_marks4 = quiz_marks4;
this->assignment_marks1 = assignment_marks1;
this->assignment_marks2 = assignment_marks2;
this->Mid_Term_Marks = Mid_Term_Marks;
this->Final_Term_Marks = Final_Term_Marks;
}

void Student::calculateQuiz()
{
this->totalQuiz = (((this->quiz_marks1 + this->quiz_marks2 + this->quiz_marks3 + this->quiz_marks4)) / 40) * 10;
}

void Student::calculateAssignment()
{
this->TotalAssignment = (((this->assignment_marks1 + this->assignment_marks2)) / 40) * 20;
}

void Student::calculateMidterm()
{
this->TotalMidterm = ((this->Mid_Term_Marks) / 40) * 30;
}

void Student::calculateFinalterm()
{
this->TotalFinalterm = ((this->Final_Term_Marks/ 60 ) * 40);
}

void Student::calculateTotalMarks()
{
this->Total_Marks = (this->totalQuiz + this->TotalAssignment + this->TotalMidterm + this->TotalFinalterm);
}
void Student::displayData()
{
calculateQuiz();
calculateAssignment();
calculateMidterm();
calculateFinalterm();
calculateTotalMarks();
cout << this->Student_Id << "\t\t\t" << this->Student_name << "\t\t" << this->TotalMidterm << "\t\t" << this->TotalFinalterm << "\t\t" << this->Total_Marks <<endl;
}

bool checkRange(int low, int high, int x)
{
return ((x - high) * (x - low) <= 0);
}
int main()
{
int quizmarks[4], assignment[2], midTerm, finalTerm;
string student_name, student_id;
bool flagquiz = true;
bool flagAssignment = true;
bool flagMidTerm = true;
bool flagFinalTerm = true;
cout << "Enter Student Id :";
cin >> student_id;
cout << "Enter Student Name :";
cin >> student_name;
for (int i = 0; i < 4; i++)
{
cout << "Enter marks for Quiz" << (i + 1) << " <out of 10>";
cin >> quizmarks[i];
do
{
if (checkRange(0, 10, quizmarks[i]))
{
flagquiz = false;
}
else
{
cout << "Invalid Marks,Quiz Marks should be between 0-10." <<endl;
cout << "Enter marks for Quiz" << (i + 1) << " <out of 10>";
cin >> quizmarks[i];
flagquiz = true;
}
} while (flagquiz);
}
for (int i = 0; i < 2; i++)
{
cout << "Enter marks for Assignment" << (i + 1) << " <out of 20>";
cin >> assignment[i];
do
{
if (checkRange(0, 20, assignment[i]))
{
flagAssignment = false;
}
else
{
cout << "Invalid Marks, Assignment Marks should be between 0-20." << endl;
cout << "Enter marks for Assignment" << (i + 1) << " <out of 20>";
cin >> assignment[i];
flagAssignment = true;
}
} while (flagAssignment);
}
cout << "Enter marks for Mid term <out of 40>";
cin >> midTerm;
do
{
if (checkRange(0, 40, midTerm))
{
flagMidTerm = false;
}
else
{
cout << "Invalid Marks, Mid term Marks should be between 0-40." <<endl;
cout << "Enter marks for Mid term <out of 40>";
cin >> midTerm;
flagMidTerm = true;
}
  } while (flagMidTerm);
cout << "Enter marks for Final term <out of 60>";
cin >> finalTerm;
do
  {
if (checkRange(0, 60, finalTerm))
{
flagFinalTerm = false;
}
else
{
cout << "Invalid Marks, Final term Marks should be between 0-60." <<
endl;
cout << "Enter marks for Final term <out of 60>";
cin >> finalTerm;
flagFinalTerm = true;
}
} while (flagFinalTerm);
Student *std = new Student[3];
 std[0] = Student("Bc0000000", "name", 2, 4, 6, 8, 11, 17, 0, 0);
 std[1].enterData(student_id, student_name, quizmarks[0], quizmarks[1],
quizmarks[2], quizmarks[3], assignment[0], assignment[1], midTerm, finalTerm);
 std[2] = Student(std[1]);
cout << "Sutdent ID"<< "\t\t"<< "StudentName"<< "\t"<< "MidTermMarks"<< "\t"<< "FinalTermMArks"<< "\t\t"<< "TotalMarks" << endl;
cout << "---------------------------------------------------------------------------------------------------------" << endl;
std[0].displayData();
std[1].displayData();
std[2].displayData();
delete []std;
return 0;
}

Output







No comments

Powered by Blogger.