C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old June 7th, 2002, 09:56 PM
Hurl§ Hurl§ is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 0 Hurl§ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation Need help with Arrays!!

I could use a real good hand with arrays. I am writing a program that does the following;

A function Inputs a subject (string Subject)
A separate function then loops the input of Student Number (int StudentNumber) and Grade (char StudentGrade) (A, B, C, D) until user exits by selecting 0 in student number.

The program must provide arrays for the following pre-written function which sorts each student number by GPA. The program must then list Student Numbers, GPA’s and the number of subjects each student number took part in;
/****************************************************************************
SortByGPAs
Process: Sort arrays in descending order by GPA - insertion sort
When GPAs are equal, sort in descending order of NumSubjs
input: int NextIndex: First unused position in arrays
int StudIds[]: array of student nos - to be sorted
int SumOfGrades[]: array of sums of grades - to be sorted
int NumSubjs[]: array of number of subjects - to be sorted
output: int StudIds[]: array of student nos - sorted
int SumOfGrades[]: array of sums of grades - sorted
int NumSubjs[]: array of number of subjects - sorted
PHP Code:
****************************************************************************/
void SortByGPAs(             // Sort arrays by GPAs
    
int NextIndex,       // IN: First unused position in arrays
    
int StudIds[],            // IN/OUT: array of student nos - to be sorted
    
int SumOfGrades[],    // IN/OUT: array of sums of grades - to be sorted
    
int NumSubjs[])
{  
    
int
        GPABy100
,         // GPA multiplied by 100 as an int
        
GPABy100Prev;     //     "         "
    
    // NextIndex is first unused position in arrays
    
for (int i 1NextIndexi++)
    {  
        
// Sort into descending GPA order - when GPAs are equal sort 
        // into descending number-of-subjects order
        // To avoid floating-point comparisons, multiply GPAs by 100 and
        // do integer comparisons
         
for (int j i&& 
           (
GPABy100 SumOfGrades[j] * 100 NumSubjs[j]) >= 
           (
GPABy100Prev SumOfGrades[j-1] * 100 NumSubjs[j-1]); j--)
         {  
             
// Swap elements if:  1) GPABy100 is greater
             //                             2) GPABy100s are equal and NumSubjs greater
             
if (GPABy100 GPABy100Prev || (GPABy100 == GPABy100Prev && 
                                          
NumSubjs[j] > NumSubjs[j-1]))
             {  
// swap elements in all arrays
                 
Swap(StudIds[j], StudIds[j-1]);    
                 
Swap(NumSubjs[j], NumSubjs[j-1]);     
                 
Swap(SumOfGrades[j], SumOfGrades[j-1]);               
             }
         }
    }    



The system must determine if the student has been entered previously for another subject, if not insert new student information into the arrays; the student number, the numerical grade for that subject and number of subjects.
Since characters are an ordered sequence character are converted to numeric equivalents.
Static_cast<int>(‘C”)

I currently have Subject as a string, StudentNumber as an integer and StudentGrade as a character, how can I put these into arrays that can be used by this function (passing through main).

As I have very basic knowledge of arrays and readings aren’t helping, thanks to anyone that can help.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Need help with Arrays!!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway