outputting a list

Hey,
The objective of REPORT function is to output a specific response to another file based on the input. I am stuck when there is a student existing and the input is z=-1. Then the output should display all of the students grade from each project. The file which the students are listed is the following, where the first column is id, then pin, and then grades for each project. I appreciate the community's help.
1
2
3
4
5
6
4
3
1111     11     90 81 91
2222     10     99 80 93
4444     44     90 84 94
3333     12     99 80 92

This is my code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  void 
P2_GRADES::P2_REPORT(int x, int y, int z)
{

	int i, FOUND, FOUND_POS, j;

	output_file << "P2 START =====================================" << endl;
        output_file << "P2 OUTPUT FROM P2_REPORT INTERFACE:" << endl;
	
	  if(x==-1 && y==-1 && z==-1)
	  {
	    P1_LIST();
	  }
	 
	  else if (x>=0 && x<=9999)
	  {
	    FOUND=0;
	    for(i=0;i<n && FOUND==0; i++)
	    {
	      if(id[i]==x && pin[i]==y)
	      {
		FOUND=1; FOUND_POS=i;
		//if (FOUND==1)
		//{
		//output_file<<"P2 THE GRADE OF STUDENT "<<id[i]<<" FOR PROJECT 1 IS "<<projects[i][1]<<endl;
		//} 
		  
	      }
	      else{}
	    }
	    
	    if (FOUND==1)
	    {
	      output_file<<"P2 THE GRADE OF STUDENT "<<id[i-1]<<" FOR PROJECT 1 IS "<<projects[i-1][1]<<endl;
	    if(FOUND==1 && z==-1)
	    {
	      for(i=0;i<n;i++)
	      {
		output_file<<"P2 THE GRADE OF STUDENT "<< x<< " FOR PROJECT "<<i<<" IS "<<projects[x][i]<< "."<<endl;
	      }
	    }
	    else if(FOUND==0) 
	    {
	      output_file<<"P2 NO SUCH STUDENT WITH ID "<<x<<"."<<endl;
	    }

this is the main
1
2
3
4
5
6
7
8
9
10
11
#include "p2.h"
// example program: main2_1.cc
int main ()
{
        P2_GRADES g;  // instantiate an object g of class P2_GRADES 

        g.P2_REPORT(1111, 11, -1);
        g.P2_SORT();

        return 0;
}
Last edited on
Nevermind I got it to work. This is the code if anyone ever needs it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
void 
P2_GRADES::P2_REPORT(int x, int y, int z)
{

	int i, FOUND, FOUND_POS, j;

	output_file << "P2 START =====================================" << endl;
        output_file << "P2 OUTPUT FROM P2_REPORT INTERFACE:" << endl;
	
	  if(x==-1 && y==-1 && z==-1)
	  {
	    P1_LIST();
	  }
	 
	  else if (x>=0 && x<=9999)
	  {
	    FOUND=0;
	    for(i=0;i<n && FOUND==0; i++)
	    {
	      if(id[i]==x && pin[i]==y)
	      {
		FOUND=1; FOUND_POS=i;
		//if (FOUND==1)
		//{
		//output_file<<"P2 THE GRADE OF STUDENT "<<id[i]<<" FOR PROJECT 1 IS "<<projects[i][1]<<endl;
		//}
		  
	      }
	      else{}
	    }
	    if(FOUND==1 && z==-1)
	    {
	      for(j=0;j<p;j++)
	      {
		output_file<<"P2 THE GRADE OF STUDENT "<< x<< " FOR PROJECT "<<j<<" IS "<<projects[i-1][j]<< "."<<endl;
	      }
	    }
	    
	    else if (FOUND==1)
	    {
	      output_file<<"P2 THE GRADE OF STUDENT "<<id[i-1]<<" FOR PROJECT 1 IS "<<projects[i-1][1]<<" ."<<endl;
	    }
	    
	    else if(FOUND==0) 
	    {
	      output_file<<"P2 NO SUCH STUDENT WITH ID "<<x<<"."<<endl;
	    }
	    
	  
	  }
	  
	  
	

	output_file << "P2 END =======================================" << endl;
	
}
Topic archived. No new replies allowed.