GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 12-Oct-2008, 19:31
ae012 ae012 is offline
New Member
 
Join Date: Oct 2008
Posts: 3
ae012 is on a distinguished road

Write a program to compute for the average grade of N scholars


i have a machine problem assignment about arrays, but this topic was least taught to us. so i only have a very little knowledge about array programming

my task is to compute for the average grade of N scholars. N will be entered on the keyboard.
The student no. and grades of the scholars in 8 subjects will also be entered by the user on the keyboard.

i have a short syntax but it seem not to be correct. please help me as i very much need this

thank you in advance


my code is this
CPP / C++ / C Code:
//ARRAY OF SCHOLARS

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>

using namespace std;


void Display(int ARR[], int SIZE, char C);
void Change(int ARR[], int SIZE);
int Increment(int x, int y);

int var_name[50];

int main()
{	
    int N;
    cout<<"Enter Number of Scholars: ";
    cin>>N;
    cout<<"\n"<<N<<" Scholars would be evaluated.\n\n";
    int j;
    int scholars[N];
    for(j=0;j<N;j++)
    {   int SN;
        cout<<"Enter Student Number for Scholar "<<j+1<<":";
        cin>>SN;
        int s;
        float GS;
        for(s=0;s<8;s++)
        {               cout<<"Enter Grade of Scholar "<<SN<<" in Subject "<<s+1<<":";
                        cin>>GS;
        }
        cout<<"\n";
    }
    cout<<"SN\tS1\tS2\tS3\tS4\tS5\tS6\tS7\tS8\tAVE\n";
    for(j=0;j<N;j++)
    {
    N=0;
    scholars[N];
    cout<<SN<<s+1<<s+2<<s+3<<s+4<<s+5<<s+6<<s+7<<s+8;
    N++;
    }
    int p;
    cin>>p;
}


output should be like this (sample only, average is not really computed)
output is for N = 2
STUDENT NO. S1 S2 S3 S4 S5 S6 S7 S8 AVERAGE
123 56 76 34 89 56 90 87 67 79.4
235 34 76 21 99 76 80 45 35 56.8
Last edited by admin : 12-Oct-2008 at 23:10. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #2  
Old 12-Oct-2008, 20:39
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Re: Help In Array Programing


Just add the score and divide by number of students.
  #3  
Old 12-Oct-2008, 20:48
ae012 ae012 is offline
New Member
 
Join Date: Oct 2008
Posts: 3
ae012 is on a distinguished road

Re: Help In Array Programing


here is the copy of my problem

and computing the average is not the only problem

Write a program to compute for the average grade of N scholars. N will be
entered on the keyboard and the Student No. and grades of the scholars in 8 subjects will be entered in tabulated form as shown below:

sample input/output display for N=5

FIRST SEMESTER:
student no. s1 s2 s3 s4 s5 s6 s7 s8 average
113 80 80 80 80 80 80 80 80 80
222 85 85 85 85 85 85 85 85 85
334 90 90 90 90 90 90 90 90 90
435 70 70 70 70 70 70 70 70 70
555 95 95 95 95 95 95 95 95 95

SECOND SEMESTER:
student no. s1 s2 s3 s4 s5 s6 s7 s8 average
222 90 90 90 90 90 90 90 90 90
334 80 80 80 80 80 80 80 80 80
555 95 95 95 95 95 95 95 95 95


FINAL REPORT:
STUDENT NO. 1ST SEM 2ND SEM AVERAGE
113 80 x x
222 85 90 87.5
334 90 80 85
435 70 x x
555 95 95 95


RANK NO. 1: STUDENT NO. 555

In the above tabulation, the Student No. and the 8 grades are keyboard input while the last column is the output of the average of the 8 grades as computed by the program. Only the scholars who maintain an average grade of 85 or higher are qualified for scholarship for the second semester. A final report at the end of the school year is generated as shown above, and the highest final average for the 2 semesters should be determined, to know who ranks first among the scholars.
  #4  
Old 12-Oct-2008, 20:54
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Help In Array Programing


Quote:
Originally Posted by ae012
i have a short syntax but it seem not to be correct.
  • When posting source code, please used [cpp] & [/cpp] tags instead of [code] & [/code] tags. This will preserve formating & color code keywords & identifiers.
  • Note that in the following:
    CPP / C++ / C Code:
        for(j=0;j<N;j++)
        {   int SN;
            cout<<"Enter Student Number for Scholar "<<j+1<<":";
            cin>>SN;
            int s;
            float GS;
            for(s=0;s<8;s++)
            {               cout<<"Enter Grade of Scholar "<<SN<<" in Subject "<<s+1<<":";
                            cin>>GS;
            }
            cout<<"\n";
        }
    SN is defined inside the block associated with the for-loop. This means that SN will not be accessible outside of this scope.

    In comparison,
    CPP / C++ / C Code:
        for(j=0;j<N;j++)
        {
        N=0;
        scholars[N];
        cout<<SN<<s+1<<s+2<<s+3<<s+4<<s+5<<s+6<<s+7<<s+8;
        N++;
        }
    
    ...uses a variable named SN, but SN is not defined. The compiler cannot resolve this dilemma, so it flags no definition of SN as an error.
  • Likewise, where is s defined?
  • What is the purpose of the following statements?
    CPP / C++ / C Code:
        N=0;
        scholars[N];
  • What is the purpose of the following statements?
    CPP / C++ / C Code:
        int p;
        cin>>p;
  • Function main() states that it returns an int. No return statement is specified.
I would recommend solving all of these problems before worrying further about averaging.
Last edited by ocicat : 12-Oct-2008 at 21:36.
  #5  
Old 12-Oct-2008, 21:49
ae012 ae012 is offline
New Member
 
Join Date: Oct 2008
Posts: 3
ae012 is on a distinguished road

Re: Help In Array Programing


thanx for the reply!

CPP / C++ / C Code:
//ARRAY OF SCHOLARS

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>

using namespace std;


int main()
{	
    int* scholars = NULL;
    int N,SN,s;
    const int counter = 1;
    float* GS = NULL;
    int average;
    cout<<"Enter Number of Scholars: ";
    cin>>N;
    
    //Initialize new Array Count
    scholars = new int[N];
    cout<<"\n"<<N<<" Scholars would be evaluated.\n\n";

    int j;
    for(j=0;j<N;j++)
    {   cout<<"Enter Student Number for Scholar "<<j+1<<":";
        cin>>scholars[j];
        GS = new float[8];
        for(s=0;s<8;s++)
        {               
                cout<<"Enter Grade of Scholar "<< scholars[j] <<" in Subject "<<s+1<<":";                        
                cin>> GS[s];
                 
        }
        cout<<"\n";
    }
    cout<<"SN\tS1\tS2\tS3\tS4\tS5\tS6\tS7\tS8\tAVE\n";
    for(j=0;j<N; j++) {
        average = 0;
        int sum = 0;
        cout<<scholars[j];
        
        for (s=0; s<8; s++) {
                cout <<"\t" << GS[s];
                sum = sum + GS[s];
        }
        
        average = sum / 8;
        cout << "\t" << average <<"\n"; 
    }
    
    
   
    int p;
    cin>>p;
}


this is only for the FIRST SEMESTER, how can i evaluate the scholars to be eligible for the 2nd semester?


thanx for the help
  #6  
Old 12-Oct-2008, 22:14
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Help In Array Programing


Quote:
Originally Posted by ae012
this is only for the FIRST SEMESTER, how can i evaluate the scholars to be eligible for the 2nd semester?
Various comments:
  • Have you covered structures yet? This would further simplify your logic, but struct's are not required to meet the requirements.
  • So far, you have retained everything needed to compute one semester. The second semester is computed in an identical fashion, so create a duplicate set of structures to retain all required information.
  • You have introduced setting the size of the arrays at runtime. All calls to operator new need to have equivalent calls to operator delete elsewhere in the code. I would suggest deleting everything at the end of main().
  • Likewise, you have hard coded values of 8 throughout the code. I assume this is an artifact which is meant to be changed.
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
where is the problem and can you fix it (php) oggie MySQL / PHP Forum 8 14-Apr-2008 16:08
Getting a line error in register oggie MySQL / PHP Forum 5 13-Apr-2008 17:16
What is an array? Howard_L C Programming Language 3 05-Oct-2007 06:11
How to sort in C++ alphabetically wilen C++ Forum 5 20-Apr-2007 15:43
Need help deleting the last element in the array headphone69 C++ Forum 2 15-Mar-2006 20:31

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:39.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.