Question

In: Computer Science

This should be written in C++. Create a class with the name "Student". private data members...

This should be written in C++.

Create a class with the name "Student".

private data members of the Student class should include:

int - rollno (roll number or id number of student)

string - name (name of student)

int - alg, datastruct, architect, proglang (hold scores out of 100 for these 4 classes)

float - per (average score of 4 classes above)

char - grade (letter grade based on per.. example 90 is an A)

public member functions of the Student class should include:

getdata() (function to accept data from user

showdata() (function to show data on screen

Create a constructor that initializes all int to 0, float to 0.0, char to ' ', name = "NoName".

Prompt the user for a valid class size.

Prompt the user for student data.

Store students in a vector.

Display student data including students average score and letter grade.

The following is an example:

Enter size of class: 0
Invalid class size

Enter size of class: 1

Enter the roll number of student: 45
Enter The Name of student: Trish Duce
Enter the grade in Algorithms out of 100: 88
Enter the grade in Data Structures out of 100: 94
Enter the grade in Architecture out of 100: 98
Enter the grade in Programming Languages out of 100: 92

Roll number of student: 45
Name of student: Trish Duce
Grade in Algorithms: 88
Grade in Data Structures: 94
Grade in Architecture: 98
Grade in Programming Languages: 92
Percentage of student is: 93
Grade of student is: A

Solutions

Expert Solution

#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
using namespace std;

// Creating the Student class
class Student
{
private:
// Declaring variable
int rollno;
string name;
int alg, datastruct, architect, proglang;
float per;
char grade;

public:
// Parameterized constructor
Student()
{
this->rollno = 0;
this->name = "NoName";
this->alg = 0;
this->datastruct = 0;
this->architect = 0;
this->proglang = 0;
this->per = 0.0;
this->grade = ' ';
}
// function declarations
void getData();
void showdata();

// Setters and getters
int getRollno()
{
return rollno;
}
void setRollno(int rollno)
{
this->rollno = rollno;
}
string getName()
{
return name;
}
void setName(string name)
{
this->name = name;
}
int getAlg()
{
return alg;
}
void setAlg(int alg)
{
this->alg = alg;
}
int getDatastruct()
{
return datastruct;
}
void setDatastruct(int datastruct)
{
this->datastruct = datastruct;
}
int getArchitect()
{
return architect;
}
void setArchitect(int architect)
{
this->architect = architect;
}
int getProglang()
{
return proglang;
}
void setProglang(int proglang)
{
this->proglang = proglang;
}
float getPer()
{
return per;
}
void setPer(float per)
{
this->per = per;
}
char getGrade()
{
return grade;
}
void setGrade(char grade)
{
this->grade = grade;
}
};

/* Function implementatin which
* gets the data entered by the user
*/
void Student::getData()
{
double average = 0.0, sum = 0.0;
cout << "Enter the roll number of student: ";
cin >> this->rollno;
cin.ignore();
cout << "Enter The Name of student:";
std::getline(std::cin, this->name);
cout << "Enter the grade in Algorithms out of 100: ";
cin >> this->alg;
cout << "Enter the grade in Data Structures out of 100: ";
cin >> this->datastruct;
cout << "Enter the grade in Architecture out of 100: ";
cin >> this->architect;
cout << "Enter the grade in Programming Languages out of 100: ";
cin >> this->proglang;
sum += this->getAlg() + this->getDatastruct() + this->getArchitect() + this->getProglang();
average = sum / 4;
this->setPer(average);
if (getPer() >= 90 && getPer() <= 100)
this->setGrade('A');
else if (getPer() >= 80 && getPer() < 90)
this->setGrade('B');
else if (getPer() >= 70 && getPer() < 80)
this->setGrade('C');
else if (getPer() >= 60 && getPer() < 70)
this->setGrade('D');
else if (getPer() < 60)
this->setGrade('F');
}

// Function which displays the Student's data
void Student::showdata()
{


cout << "Roll number of student: " << this->getRollno() << endl;
cout << "Name of student: " << this->getName() << endl;
cout << "Grade in Algorithms: " << this->getAlg() << endl;
cout << "Grade in Data Structures: " << this->getDatastruct() << endl;
cout << "Grade in Architecture: " << this->getArchitect() << endl;
cout << "Grade in Programming Languages: " << this->getProglang() << endl;
cout << "Percentage of student is: " << this->getPer() << endl;
cout << "Grade of student is: " << this->grade << endl;
}
int main()
{


// Declaring vector
vector<Student> vec;
// Declaring variables
int size;

// Getting the valid size entwered by the user
while (true)
{
cout << "Enter the size of the class :";
cin >> size;
if (size <= 0)
{
cout << "Invalid class size" << endl;
continue;
}
else
break;
}


/* Getting the data entered by user
* by calling the getData() function
* on the Student class
*/
for (int i = 0; i < size; i++)
{
Student st;
st.getData();
vec.push_back(st);
}
cout << endl;
/* Displaying the data entered by user
* by calling the showData() function
* on the Student class
*/
for (int i = 0; i < size; i++)
{
vec[i].showdata();
}


return 0;
}

_________________

output:

_______________Thank You


Related Solutions

C++ Create a class for working with fractions. Only 2 private data members are needed: the...
C++ Create a class for working with fractions. Only 2 private data members are needed: the int numerator of the fraction, and the positive int denominator of the fraction. For example, the fraction 3/7 will have the two private data member values of 3 and 7. The following methods should be in your class: a. A default constructor that should use default arguments in case no initializers are included in the main. The fraction needs to be stored in reduced...
Create a class called Car (Car.java). It should have the following private data members: • String...
Create a class called Car (Car.java). It should have the following private data members: • String make • String model • int year Provide the following methods: • default constructor (set make and model to an empty string, and set year to 0) • non-default constructor Car(String make, String model, int year) • getters and setters for the three data members • method print() prints the Car object’s information, formatted as follows: Make: Toyota Model: 4Runner Year: 2010 public class...
Create a class called Car (Car.java). It should have the following private data members: • String...
Create a class called Car (Car.java). It should have the following private data members: • String make • String model • int year Provide the following methods: • default constructor (set make and model to an empty string, and set year to 0) • non-default constructor Car(String make, String model, int year) • getters and setters for the three data members • method print() prints the Car object’s information, formatted as follows: Make: Toyota Model: 4Runner Year: 2010 public class...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance:...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance: balance held in the account interestRate: annual interest rate. accountID: unique 3 digit account number assigned to each BankAccount object. Use a static data member to generate this unique account number for each BankAccount count: A static data member to track the count of the number of BankAccount objects created. Member Functions void withdraw(double amount): function which withdraws an amount from accountBalance void deposit(double...
Write a class called Person that has two private data members - the person's name and...
Write a class called Person that has two private data members - the person's name and age. It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Write a separate function (not part of the Person class) called std_dev that takes as a parameter a list of Person objects and returns the standard deviation of all their ages (the population standard deviation that uses a denominator...
Write a class called Person that has two private data members - the person's name and...
Write a class called Person that has two private data members - the person's name and age. It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Write a separate function (not part of the Person class) called basic_stats that takes as a parameter a list of Person objects and returns a tuple containing the mean, median, and mode of all the ages. To do this,...
create a class in C++ having the following 4 private members: one double variable representing the...
create a class in C++ having the following 4 private members: one double variable representing the balance of a bank account on string variable representing the bank account number a function to deposit money from the bank account a function to withdraw money from the bank account the following 2 public members: -two wrapper functions. - one parameterless constructor - one constructor initializing the account balance and account number - sample: #include <iostream> using namespace std; class account { public:...
Create a class for working with complex numbers. Only 2 private float data members are needed,...
Create a class for working with complex numbers. Only 2 private float data members are needed, the real part of the complex number and the imaginary part of the complex number. The following methods should be in your class:a. A default constructor that uses default arguments in case no initializers are included in the main.b. Add two complex numbers and store the sum.c. Subtract two complex numbers and store the difference.d. Multiply two complex numbers and store the product.e. Print...
Rectangle Class in C++ Create a Rectangle class that has two data members: length_ and width_....
Rectangle Class in C++ Create a Rectangle class that has two data members: length_ and width_. Create the corresponding accessor and mutator functions to access and change both data members. Create a member function area that returns the area of the Rectangle object. Finally, create a function longest_rectangle that accepts two Rectangle objects as parameters and returns the Rectangle object with the longer length. Write the Rectangle class and the longest_rectangle function prototype in rectangle.hpp. Take note that longest_rectangle is...
WRITE IN C++ Create a class named Coord in C++ Class has 3 private data items...
WRITE IN C++ Create a class named Coord in C++ Class has 3 private data items               int xCoord;               int yCoord;               int zCoord; write the setters and getters. They should be inline functions               void setXCoord(int)             void setYCoord(int)            void setZCoord(int)               int getXCoord()                     int getYCoord()                   int getZCoord() write a member function named void display() that displays the data items in the following format      blank line      xCoord is                          ????????      yCoord is                          ????????      zCoord...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT