Link to home
Start Free TrialLog in
Avatar of freebuddy
freebuddy

asked on

PARTIALLY FILLED ARRAYS


Dear fellows, I'm requesting your help urgently please, I have few time, I'd appreciate clear and straight answers.

Im supposed to write a program that computes grades for a class btw 10 && 50 students. The program reads in score in 0-100 from a data file and then outputs the grades,identifying each student by number.

I'm using right now 3 functions for this program, because I need to get the average and another funcion to compare. I have a code but its not running, so I'm asking, could you anyone please explain to me hwo can I use the data file for the scores and just what code could go in the compare function, any loop or soemthing like that? Im not sure bout this few aspects.

I'd appreciate your answers, thanks a lot people.

Freebuddy
Avatar of freebuddy
freebuddy

ASKER


by the way, just to give you an idea, this the problem description: write a program that computes grades for a class of 10 and 50 students. Program reads in a score in range 0-100 for each student from a "data file" and then outputs grades,identifying each student by number. Grades are determined: any student with 10 points below averate>F any student with score above and at most 10 gets a C and any student who gets abovew that, gets an A. There are no D's or B's. Input file contains scores like this:

85.7
56.7
etc.

Thats it guys, Im not asking you to solve me this problem but I need as much hints as possible. I apologize but I have big problems with this.

Thanks fellows,

Freebuddy
Post the code that you have so far.
ASKER CERTIFIED SOLUTION
Avatar of masnrock
masnrock
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok guys, here's a rough code of what I got, I'm having problems on the FILE open part, Im not sure and also on how to compare the arrays so that each score for each X student... the following code has lots of mistakes, but is not that I dont know, is just roughly what Im thinking so please do not tell me that things like this { are missing or something, this is just what I think, but I just dont know how to put it in order or if my variables are ok, please check it. My problems: file open and compare.

#include<stdio.h>
#define ID 50
#define GRADE 40
#define EOF -1
void get_data(double scores[],int *count);
double average(double avg);
void compare(double scores[],int student[]);

int
main(void)
{
  double points[];
  int  *count ;
  int student[ID] ;
 char letter[GRADE];

average(avg);

printf(“ The average is %lf\n”,&avg);

return(0);

}

void get_data(double scores[],int *count)
{
 FILE *inp;
 int i ;
int *count ;
int stats ;
double points[] ;

inp= fopen(“points.dat”,”r”);
printf(“points\n”);

stats=fscanf(inp,”%lf”,&points);
while(stats!=EOF){
printf(“%lf”, points)



double average(double avg)
{
int i;

for(i=10;i<ID;i++)

avg=(scores[]+scores[])/scores[]

return(avg);
}

ok guys, here is the latest code I got:

Include<stdio.h>
#define STUD 40
#define SENTINEL 99
#define GRADES 40
void get_data(double scores[], int *counts);
double average(double const scores[],int count);
void compare(double scores[],double avg, int count);

int
main(void)
{
 int num[STUD];
 char grad[GRADES];
double scor[];
int count;

average(scor[],count);
printf(“The average is %lf\n”,average(scor,count));

return(0);
}

void get_data(double scores[],int *count)
{
 double nums;
 int c=0;

FILE *inp,*outp;
int stats;
inp=fopen(“scoring.dat”,”r”);
outp=fopen(“scoring.out”,”w”);

fprintf(outp,”scoring\n”);
fprintf(outp,”---------\n”);

stats=fscanf(inp,”%lf”,&nums);
while(stats==1 && c!=SENTINEL){
scores[c]=nums;
c++;
status=fscanf(inp,”%lf”,&nums);
}*count=c
}

void compare(double scores[],double avg, int count)
{
 int i;

 for(i=0;i<count;i++){
if(scores[i]<avg-10){
printf(“F”);
}
else if(scores[i]>avg){
printf(“C”);
{
else{
printf(A);
}
}
}

double average(double scores[],int count)
{
 int i;
double sum=0.0;
for(i=0;i<count;i++)
sum+=scores[];

return(sum/count);

}


I need help as soon as possible please, I'm confused about how to parallel all so my output looks like this:

student        Score         Grade
    1              56.8            F
    2              90.6            A
    3...           87.6...         A

how? I'd appreciate that. Also I think my "compare function " is wrong, but I im not sure, in the compare function im supposed to compare each score with the average to see if the student gets F, A or C.

Please I need this soon.

Thank you guys,

Good night.
What is the condition to be A, F, C?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
fellows, I got this code, and im only having one error called "segmentation fault(core dumped)". I think is because I havent found how to arrange in a parallel ways the arrays, im confused in which part of the problem should I used a for-loop to arrange num[STUD] and grad[GRADES]. I don't know how to proceed oh relating them with the scores in the get data function. PLEASE HELP

   
#include<stdio.h>
#define STUD 40
#define SENTINEL 99
#define GRADES 40
void get_data(double scores[], int *count);
double average(double const scores[],int count);
void compare(double scores[],double avg, int count);

int
main(void)
{
 int num[STUD];
 char grad[GRADES];
 double scor[100];
 int count;
 double avg;
 int i;

get_data(scor,&count);
avg=average(scor,count);
printf("The average is %lf\n",avg);


return(0);
}

void get_data(double scores[],int *count)
{
 double scor;
 int c=0;

FILE *inp,*outp;
int stats;
inp=fopen("scoring.dat","r");
outp=fopen("scoring.out","w");

fprintf(outp,"scoring\n");
fprintf(outp,"---------\n");

stats=fscanf(inp,"%lf",&scor);
while(stats==1 && c!=SENTINEL){
scores[c]=scor;
c++;
stats=fscanf(inp,"%lf",&scor);
}*count=c;
}

void compare(double scores[],double avg, int count)
{
 int i;

 for(i=0;i<count;i++){
if(scores[i]<avg-10){
printf("F");
}
else if(scores[i]>avg-10){
printf("C");
}
else{
printf("A");
}
}
}

double average(double const scores[],int count)
{
 int i;
double sum=0.0;
for(i=0;i<count;i++)
sum+=scores[i];

return(sum/count);

}