i want to align the output, where it says gpa

#include <iostream>
#include <iomanip>
#include <string>
#include <time.h>
using namespace std;

class Student
{
private:
string name;
double gpa;
public:
Student(){name="unkown"; gpa=0.0;}
Student(string n){name=n;}
double getGPA(){return gpa;}
void setName(string n){name=n;}
string getName(){return name;}
void setGPA()
{
srand (time(0));
double r = rand()%41+0;
r = r*0.1;
gpa=r;
}



void display()
{
cout<<getName()<<setw(10)<<" GPA:"<<fixed<<setprecision(1)<<getGPA()<<endl;
}

void DISPLAY()
{
cout<<getName()<<" GPA: "<<getGPA()<<endl;
}
};

int main()
{
Student s[5];
string name;
double highest=0.0;
bool count[5];

cout<<"Please enter the names of five people."<<endl;

for (int x=0; x<5; x++)
{
cin>>name;
s[x].setName(name);
s[x].setGPA();
}

system("cls");
cout<<"Name"<<endl;
cout<<"------------------"<<endl;
for (int x=0; x<5; x++)
{
s[x].display();
}
cout<<"-------------------\n"<<endl;
for (int x=0; x<5; x++)
{
if (highest<s[x].getGPA())
{
highest=s[x].getGPA();
}
}

for (int x=0; x<5; x++)
{
count[x]=(false);
if (s[x].getGPA()==highest)
{
count[x]=(true);
}
}

cout<<"Highest GPA(s)"<<endl;
cout<<"------------"<<endl;
for (int x=0; x<5; x++)
{
if (count[x]==true)
{
s[x].DISPLAY();
}
}

system ("pause");
return 0;
}
1) Use Code Blocks
2) We need more information than, "I want to do X."
3) I see GPA on multiple lines. Please specify one.
void display()
{
cout<<getName()<<setw(10)<<" GPA:"<<fixed<<setprecision(1)<<getGPA()<<endl;
}

On this section
What do you want to do on this section? You say you want to align it, but what do you want to align it with?

1
2
3
4
void display()
{
    cout<<getName()<<setw(10)<<" GPA:"<<fixed<<setprecision(1)<<getGPA()<<endl;
}


and you're still not using code blocks. After you enter code, select all of it and click the button to the right that looks like <>.
Last edited on
Topic archived. No new replies allowed.