•
•
•
•
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
![]() |
•
•
Join Date: Oct 2004
Posts: 11
Reputation:
Rep Power: 4
Solved Threads: 0
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 ><
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 ><
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
*/![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- average array (C++)
- Simple array/class problem (dot operator)??? (C++)
- Need help with Arrays (Visual Basic 4 / 5 / 6)
- Converting Struct to class lost with pointers (C++)
Other Threads in the C++ Forum
- Previous Thread: Vectors, Functions, and Sorting... oh my!
- Next Thread: cin.peek



Linear Mode