hey guys!
mind if you help me here?
we were asked to make a grading system.
here is my code..
#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;
void main()
{
system("CLS");
char fn[50],ln[50];
string *name, *enam, temp, *R, wN, fin, lan;
double gr, *g, temp2, *EQ;
int x,y;
name= new string [5];
enam= new string [5];
g=new double [5];
EQ=new double[1];
R=new string[1];
char ans='N';
do
{
cout<<"\t\t\t******************"<<endl;
cout<<"\t\t\t Grading System "<<endl;
cout<<"\t\t\t******************"<<endl;
for (x=0; x<5; x++)
{
cout<<"Enter Last Name: ";
gets(ln);
*(name+x)=ln;
cout<<"Enter First Name:";
gets(fn);
*(enam+x)=fn;
cout<<"\n"<<"Enter Grades..."<<endl;
*(g+x)=0;
cout<<"\n\t"<<"Quizzes:\t";
cin>>gr;
*(g+x)+=gr*0.25;
cout<<"\t"<<"Assignments:\t";
cin>>gr;
*(g+x)+=gr*0.10;
cout<<"\t"<<"Long Exams:\t";
cin>>gr;
*(g+x)+=gr*0.25;
cout<<"\t"<<"Final Exams:\t";
cin>>gr;
*(g+x)+=gr*0.40;
cout<<"\n\t"<<"Total Grade:"<<*(g+x)<<endl<<endl;
cin.ignore();
lan=ln;
fin=fn;
wN=lan+","+fin;
*(name+x)=wN;
cout<<endl;
}//end for
for(x=0; x<5; x++)
{
for(y=x+1; y<5; y++)
{
if (*(name+x)>*(name+y))
{
temp = (*(name+x));
*(name+x) = (*(name+y));
*(name+y) = temp;
temp2 = (*(g+x));
*(g+x) = (*(g+y));
*(g+y) = temp2;
}//end if
}//end for
}//end for
system("CLS");
cout<<"Unsorted (Sorted by Names)"<<endl;
cout<<setw(33)<<left<<"Name"<<setw(8)<<"Grade"<<setw(10)<<"Equivalent"<<setw(18)<<right<<"Remarks"<<endl;
for (x=0; x<5; x++)
{
if(*(g+x)>=0&&*(g+x)<=69.49)
{
*EQ=0.5;
*R="Needs Improvement";
}
else if(*(g+x)>=69.5&&*(g+x)<=74.49)
{
*EQ=1.0;
*R="Study Harder";
}
else if(*(g+x)>=74.5&&*(g+x)<=79.49)
{
*EQ=1.5;
*R="Study Harder";
}
else if(*(g+x)>=79.5&&*(g+x)<=84.49)
{
*EQ=2.0;
*R="More Practice";
}
else if(*(g+x)>=84.5&&*(g+x)<=88.49)
{
*EQ=2.5;
*R="Average";
}
else if(*(g+x)>=88.5&&*(g+x)<=92.49)
{
*EQ=3.0;
*R="Satisfactory";
}
else if(*(g+x)>=92.5&&*(g+x)<=96.49)
{
*EQ=3.5;
*R="Satisfactory";
}
else if(*(g+x)>=96.5&&*(g+x)<=100)
{
*EQ=4.0;
*R="Excellent";
}
cout<<endl<<setw(33)<<left<<*(name+x)<<setw(10)<<*(g+x)<<setw(17)<<*EQ<<setw(18)<<right<<*R<<endl;
}//end for
for(x=0; x<5; x++)
{
for(y=x+1; y<5; y++)
{
if (*(g+x)<*(g+y))
{
temp = (*(name+x));
*(name+x) = (*(name+y));
*(name+y) = temp;
temp2 = (*(g+x));
*(g+x) = (*(g+y));
*(g+y) = temp2;
}
}
}
cout<<endl<<"Sorted (Sorted by Grades)"<<endl;
cout<<setw(33)<<left<<"Name"<<setw(8)<<"Grade"<<setw(10)<<"Equivalent"<<setw(18)<<right<<"Remarks"<<endl;
for (x=0; x<5; x++)
{
if(*(g+x)>=0&&*(g+x)<=69.49)
{
*EQ=0.5;
*R="Needs Improvement";
}
else if(*(g+x)>=69.5&&*(g+x)<=74.49)
{
*EQ=1.0;
*R="Study Harder";
}
else if(*(g+x)>=74.5&&*(g+x)<=79.49)
{
*EQ=1.5;
*R="Study Harder";
}
else if(*(g+x)>=79.5&&*(g+x)<=84.49)
{
*EQ=2.0;
*R="More Practice";
}
else if(*(g+x)>=84.5&&*(g+x)<=88.49)
{
*EQ=2.5;
*R="Average";
}
else if(*(g+x)>=88.5&&*(g+x)<=92.49)
{
*EQ=3.0;
*R="Satisfactory";
}
else if(*(g+x)>=92.5&&*(g+x)<=96.49)
{
*EQ=3.5;
*R="Satisfactory";
}
else if(*(g+x)>=96.5&&*(g+x)<=100)
{
*EQ=4.0;
*R="Excellent";
}
cout<<endl<<setw(33)<<left<<*(name+x)<<setw(10)<<*(g+x)<<setw(17)<<*EQ<<setw(18)<<right<<*R<<endl;
}//end for
}//end do
while(ans=='y' || ans=='Y');
}//end main
but i was experimenting and thinking if i could use void functions and do it like this..
#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;
void showArray(string [], int);
void sortName(string [], int);
void sortGrade(string [], int);
void main()
{
system("CLS");
char fn[50],ln[50];
string *name, *enam, temp, *R, wN, fin, lan;
double gr, *g, *EQ;
int x;
name= new string [5];
enam= new string [5];
g=new double [5];
EQ=new double[1];
R=new string[1];
char ans='N';
do
{
cout<<"\t\t\t******************"<<endl;
cout<<"\t\t\t Grading System "<<endl;
cout<<"\t\t\t******************"<<endl;
for (x=0; x<5; x++)
{
cout<<"Enter Last Name: ";
gets(ln);
*(name+x)=ln;
cout<<"Enter First Name:";
gets(fn);
*(enam+x)=fn;
cout<<"\n"<<"Enter Grades..."<<endl;
*(g+x)=0;
cout<<"\n\t"<<"Quizzes:\t";
cin>>gr;
*(g+x)+=gr*0.25;
cout<<"\t"<<"Assignments:\t";
cin>>gr;
*(g+x)+=gr*0.10;
cout<<"\t"<<"Long Exams:\t";
cin>>gr;
*(g+x)+=gr*0.25;
cout<<"\t"<<"Final Exams:\t";
cin>>gr;
*(g+x)+=gr*0.40;
cout<<"\n\t"<<"Total Grade:"<<*(g+x)<<endl<<endl;
cin.ignore();
lan=ln;
fin=fn;
wN=lan+","+fin;
*(name+x)=wN;
cout<<endl;
}//end for
system("CLS");
cout<<"Unsorted (Sorted by Names)"<<endl;
cout<<setw(33)<<left<<"Name"<<setw(8)<<"Grade"<<setw(10)<<"Equivalent"<<setw(18)<<right<<"Remarks"<<endl;
cout<<endl<<"Sorted (Sorted by Grades)"<<endl;
cout<<setw(33)<<left<<"Name"<<setw(8)<<"Grade"<<setw(10)<<"Equivalent"<<setw(18)<<right<<"Remarks"<<endl;
}//end do
while(ans=='y' || ans=='Y');
}//end main
void sortName(string [], int x, int y, double temp2);
{
for(x=0; x<5; x++)
{
for(y=x+1; y<5; y++)
{
if (*(name+x)>*(name+y))
{
temp = (*(name+x));
*(name+x) = (*(name+y));
*(name+y) = temp;
temp2 = (*(g+x));
*(g+x) = (*(g+y));
*(g+y) = temp2;
}//end if
}//end for
}//end for
}//end function sortName
void sortGrade(string [], int);
{
for(x=0; x<5; x++)
{
for(y=x+1; y<5; y++)
{
if (*(g+x)<*(g+y))
{
temp = (*(name+x));
*(name+x) = (*(name+y));
*(name+y) = temp;
temp2 = (*(g+x));
*(g+x) = (*(g+y));
*(g+y) = temp2;
}//end if
}//end for
}//end for
}//end function sortGrade
void showArray(string name[], int x,double g,double *EQ,string *R)
{
for (x=0; x<5; x++)
{
if(*(g+x)>=0&&*(g+x)<=69.49)
{
*EQ=0.5;
*R="Needs Improvement";
}
else if(*(g+x)>=69.5&&*(g+x)<=74.49)
{
*EQ=1.0;
*R="Study Harder";
}
else if(*(g+x)>=74.5&&*(g+x)<=79.49)
{
*EQ=1.5;
*R="Study Harder";
}
else if(*(g+x)>=79.5&&*(g+x)<=84.49)
{
*EQ=2.0;
*R="More Practice";
}
else if(*(g+x)>=84.5&&*(g+x)<=88.49)
{
*EQ=2.5;
*R="Average";
}
else if(*(g+x)>=88.5&&*(g+x)<=92.49)
{
*EQ=3.0;
*R="Satisfactory";
}
else if(*(g+x)>=92.5&&*(g+x)<=96.49)
{
*EQ=3.5;
*R="Satisfactory";
}
else if(*(g+x)>=96.5&&*(g+x)<=100)
{
*EQ=4.0;
*R="Excellent";
}
cout<<endl<<setw(33)<<left<<*(name+x)<<setw(10)<<*(g+x)<<setw(17)<<*EQ<<setw(18)<<right<<*R<<endl;
}//end for
}//end function showArray
but it gives me 19 errors.
can you please help me?
thanks in advance:)