User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 427,848 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,813 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 5354 | Replies: 1
Reply
Join Date: Oct 2004
Posts: 11
Reputation: tyalangan is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
tyalangan tyalangan is offline Offline
Newbie Poster

Getting a Grade Average

  #1  
Dec 9th, 2004
hey everyone. School is finally over (heck yes!) and next semester I'm moving onto C++, kinda nerve recking. I don't have a good C backround yet. So I'm working on some problems from our text book over the holidays. (If anyone has some interesting problems/programs that I could practice they would be appreciated) Anyway, I'm working on a problem now that finds 5 students grades I was wondering if you could help me out with it.

Program that prints the average for each student in the class(I know I'm going to use some arrays and pointers... I just don't know how to set it up)

"A"=4
"B"=3
"C"=2
"D"=1
"F"=0

Number of students is 5(just picked a number)
each student has 4 grades
the user is going to input all the information for each student
calculate grade average
then output information of student(name, id) and the students grade average

Any help would be appreciated... or I'll be stuck on it all break... lol ><
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Posts: 3,649
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 144
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Getting a Grade Average

  #2  
Dec 9th, 2004
Some ideas:
#include <stdio.h>

struct student
{
   int     id;
   char    name [ 32 ];
   double  grade [ 4 ];
};

void show(struct student *student)
{
   static const char letter[] = "FDCBA";
   size_t i;
   double sum = 0;
   for ( i = 0; i < sizeof student->grade / sizeof *student->grade; ++i )
   {
      sum += student->grade[i];
   }
   sum /= i;
   printf("%3d %-31s %c\n", student->id, student->name, letter [ (int)sum ] );
}

int main(void)
{
   struct student coder[] =
   {
      { 123, "Slim Pickens",  {1,2,3,4} },
      { 125, "Guy Wire",      {2,2,3,2} },
      { 128, "MaeFlowers",    {0,1,1,1} },
      { 132, "June Meadows",  {2,1,1,2} },
      { 121, "April Showers", {3,3,3,3} },
      { 119, "Les Ismoore",   {1,2,3,4} },
      { 137, "Harry Legg",    {3,2,3,3} },
      { 142, "Sara Bellum",   {4,2,3,4} },
      { 159, "Pete Moss",     {4,4,4,4} },
   };
   size_t i;
   for ( i = 0; i < sizeof coder / sizeof *coder; ++i )
   {
      show(&coder[i]);
   }
   return 0;
}

/* my output
123 Slim Pickens                    C
125 Guy Wire                        C
128 MaeFlowers                      F
132 June Meadows                    D
121 April Showers                   B
119 Les Ismoore                     C
137 Harry Legg                      C
142 Sara Bellum                     B
159 Pete Moss                       A
*/
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 3:17 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC