What am I doing wrong? I am supposed to do a class of Student, enter the functions and display all of the students that has a GPA equal to or greater than 3.0 #include #include 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 setFullName(string studentName) { this->Full_Name = studentName; } //return student name function string getFullName() { return Full_Name; } //function to get student GPA void setStudentGPA(float studentGpa) { this->Student_GPA = studentGpa; } //member function to return student name float getStudentGPA() { return Student_GPA; } //member function to get student Rank void setStudentRank(int studentRank) { this->Student_Rank = studentRank; } //member function to return student name int getStudentRank() { return Student_Rank; } }; int main() { Student S; //variable declaration int Number_Student; //prompt user to enter total number of student cout << "Please input the total students: "; cin >> Number_Student; //variable declaration string studentName[20]; float studentGpa; int studentRank; //prompt user to enter name GPA and rank for (int i = 0; i < Number_Student; i++) { cout << "\nEnter record for Student " << i + 1; cout << "\nName: "; cin.get(); getline(cin >> ws, studentName[i]); cout << "GPA: "; cin >> studentGpa; cout << "rank: "; cin >> studentRank; //set name GPA and rank in array S.setFullName(studentName[i]); S.setStudentGPA(studentGpa); S.setStudentRank(studentRank); } //Shows the students that are eligible for scholarship cout << "\nThe Following students are eligible for scholarship: "; for (int i = 0; i < Number_Student; i++) { float studentGpa = S.getStudentGPA(); if (studentGpa >= 3.0) { cout << "\n " << S.getFullName()<<"\n"; } } system("pause"); return 0; }
What am I doing wrong? I am supposed to do a class of Student, enter the functions and display all of the students that has a GPA equal to or greater than 3.0
#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 setFullName(string studentName)
{
this->Full_Name = studentName;
}
//return student name function
string getFullName()
{
return Full_Name;
}
//function to get student GPA
void setStudentGPA(float studentGpa)
{
this->Student_GPA = studentGpa;
}
//member function to return student name
float getStudentGPA()
{
return Student_GPA;
}
//member function to get student Rank
void setStudentRank(int studentRank)
{
this->Student_Rank = studentRank;
}
//member function to return student name
int getStudentRank()
{
return Student_Rank;
}
};
int main()
{
Student S;
//variable declaration
int Number_Student;
//prompt user to enter total number of student
cout << "Please input the total students: ";
cin >> Number_Student;
//variable declaration
string studentName[20];
float studentGpa;
int studentRank;
//prompt user to enter name GPA and rank
for (int i = 0; i < Number_Student; i++)
{
cout << "\nEnter record for Student " << i + 1;
cout << "\nName: ";
cin.get();
getline(cin >> ws, studentName[i]);
cout << "GPA: ";
cin >> studentGpa;
cout << "rank: ";
cin >> studentRank;
//set name GPA and rank in array
S.setFullName(studentName[i]);
S.setStudentGPA(studentGpa);
S.setStudentRank(studentRank);
}
//Shows the students that are eligible for scholarship
cout << "\nThe Following students are eligible for scholarship: ";
for (int i = 0; i < Number_Student; i++)
{
float studentGpa = S.getStudentGPA();
if (studentGpa >= 3.0)
{
cout << "\n " << S.getFullName()<<"\n";
}
}
system("pause");
return 0;
}

Task :
- C++ Code.
- The task is to debug the code and correct the errors.
Step by step
Solved in 3 steps with 1 images









