Hi All
im new to c++
i got an assignment to make a grade sheet. using 3d arrays
but now i am having problem with displaying result.
when only 1 subject it works fine but it doesn't work for 2 or more subjects
need help fast.
here's my attempt
Code:
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
float str2flt(string str)
{
float i;
stringstream iss(str);
iss >> i;
return i;
}
string flt2str(float no)
{
stringstream iss;
iss << no;
return iss.str();
}
/* Making an 3d array of string type all the input paramters are given by user (no of grade sheets, Students, and no. of evaluations) */
void main ()
{
string ***array={0};
int *data={0}; // for remembering individual input for no. of students of diffrent subjects
float j,u,n,i,ax,a=0;
int sub,std,ppr;
cout<<"Enter No. Of Subjects : ";
cin>>sub;
data=new int [sub];
for(int su=0;su<sub;su++)
{
array=new string **[sub]; //x
cout<<"Enter No. Of Students for subject no. "<<su+1<<" : ";
cin>>std;
data[su]=std;
array[su]=new string *[std+1]; //y +1 because of in 0 0 0 name of subject will be stored
cout<<"Enter No. Of Evaluations for subject no. "<<su+1<<" : ";
cin>>ppr;
for(int p=0;p<=std;p++)
{
array[su][p]=new string [ppr+3]; /* z +3 cuz on location [o][o][n] name of students will be stored,
on [x][y][ppr+1] avrg will b stored and on [x][y][ppr+2] grade will be stored */
}
// declartion completed
cout<<"Enter Name Of The Subject no. "<<su+1<<" (no Spaces) : ";
cin>>array[su][0][0];
cout<<"Please Input Evaluation Weightages for Subject "<<array[su][0][0]<<" (ex:0.3 for 30%)\n";
for(int w=1;w<=ppr;w++)
{
do{
cout<<"Enter Weightage for evaluation no. "<<w<<" : ";
cin>>array[su][0][w];
}while(str2flt(array[su][0][w]) > 1 || str2flt(array[su][0][w]) <0);
}
for(int s=1;s<=std;s++)
{
cout<<"Enter Name of Student no. "<<s<<" For Subject of "<<array[su][0][0]<<" (0-100): ";
cin>>array[su][s][0];
for(int no=1;no<=ppr;no++)
{
do{
cout<<"Enter Score of "<<array[su][s][0]<<" for evaluation no "<<no<<" : ";
cin>>array[su][s][no];
}while(str2flt(array[su][s][no]) >100 || str2flt(array[su][s][no]) <0);
}
}
//data input complete
for(int x=1;x<=ppr;x++) // on z
{
a+=str2flt(array[su][0][x]);
}
array[su][0][ppr+1]=flt2str(a);// w(normalizer) calculated and stored on [0][0][ppr+1]
for(int avg=1;avg<=std;avg++) // on y
{
a=0;
for(int sn=1;sn<=ppr;sn++) // on z
{
j=str2flt(array[su][avg][sn]);
u=str2flt(array[su][0][sn]);
n=j*u;
i=str2flt(array[su][0][ppr+1]);
ax=n /i;
a+=ax;
}
array[su][avg][ppr+1]=flt2str(a);
}
//average calculate wid proper weights and normalized
for(int g=1;g<=std;g++)
{
int chk;
chk=str2flt(array[su][g][ppr+1]);
if(chk < 60)
array[su][g][ppr+2]='F';
else if(chk <70)
array[su][g][ppr+2]='D';
else if(chk<80)
array[su][g][ppr+2]='C';
else if(chk<90)
array[su][g][ppr+2]='B';
else
array[su][g][ppr+2]='A';
}
}
/* OutPut Code */
for(int t=0;t<sub;t++)
{
cout<<array[t][0][0]<<"\n";
int ou=1;
while(ou<=data[t])
{
cout<<array[t][ou][0]<<"\t";
cout<<array[t][ou][ppr+1]<<"\t";
cout<<array[t][ou][ppr+2]<<endl;
ou++;
}
}
cout<<"\n\n>------------------------------------------------------------------------------<";
}//main end