there a reason why the system takes off the first letter of the name when it shows the user with the highest GPA? How can I fix it. The bug is in bold. Thank you! #include "stdafx.h" #include #include using namespace std; //declare Student Class class Student { //private member of class private:
Is there a reason why the system takes off the first letter of the name when it shows the user with the highest GPA? How can I fix it. The bug is in bold. Thank you!
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
//declare Student Class
class Student
{
//private member of class
private:
string Full_Name;
float Student_GPA;
int Student_Rank;
//public class members
public:
//function to get student name
void setStudentdata(string SN, float GPA, int rank)
{
Full_Name = SN;
Student_GPA = GPA;
Student_Rank = rank;
}
//return student name function
void getStudentdata(string &SN, float &GPA, int &rank)
{
SN = Full_Name;
GPA = Student_GPA;
rank = Student_Rank;
}
};
int main()
{
Student info[3];
//variable declaration
string studentName;
float studentGpa;
int studentRank;
//prompt user to enter name GPA and rank
for (int i = 0; i < 3; i++)
{
cout << "\nEnter record for Student " << i + 1;
cout << "\nName: ";
cin.get();
getline(cin >> ws, studentName);
cout << "GPA: ";
cin >> studentGpa;
cout << "rank: ";
cin >> studentRank;
info[i].setStudentdata(studentName, studentGpa, studentRank);
}
//Shows the student which got highest GPA
float highest = -1;
int index = -1;
for (int i = 0; i < 3; i++)
{
info[i].getStudentdata(studentName, studentGpa, studentRank);
if (highest < studentGpa)
{
index = i;
highest = studentGpa;
}
}
info[index].getStudentdata(studentName, studentGpa, studentRank);
cout << "\nStudent with highest GPA: " << endl;
cout << "Name: " << studentName << endl;
cout << "GPA: " << studentGpa << endl;
cout << "Rank: " << studentRank << endl;
cout << "Congratulations " << studentName << "!\n" << endl;
both of the bold shows the username that is taking off the first letter of name.
system("pause");
return 0;
}
Here have to determine about output correction of c++ code.
Step by step
Solved in 4 steps with 2 images