Chiuso

Write some Software

Questo progetto è stato assegnato a HafizShahan per $25 USD.

Ottieni preventivi gratuiti per un progetto come questo
Datore di Lavoro impegnato
Budget del Progetto
$10 - $30 USD
Offerte Totali
12
Descrizione del Progetto

I need a C program that builds on already existing code:

#include<stdio.h>

#include<stdlib.h>

//Taking the default size is 20 and if required it will be increased or decreased

int arraySize = 20;

//Taking the input from user and adjusting the arraySize based on number of inputs

void checkAndReallocateOnlyUsedLocations(double * arr , int count)

{

if(count < arraySize)

{

arr = realloc(arr , count * sizeof(double));

arraySize = count;

}

}

void takeInputGrades(double * arr)

{

double x = 0;

printf("Please enter gradres -1 to end: \n");

int count = 0;

while(x != [url removed, login to view])

{

scanf("%lf" , &x);

arr[count++] = x;

if(count == arraySize)

{

arraySize *= 2;

arr = realloc(arr,arraySize * sizeof(double));

}

}

checkAndReallocateOnlyUsedLocations(arr,count-1);

}

//Finding the average

double findAvg(double * arr)

{

int i = 0 ;

double sum = 0.0;

for(i = 0 ; i < arraySize ; i++)

{

sum += arr[i];

}

return (sum / arraySize);

}

//Finding the highest

double findHighest(double * arr)

{

double highest = arr[0];

int i = 0 ;

for(i = 1; i < arraySize ; i++ )

{

if(arr[i] > highest)

highest = arr[i];

}

return highest;

}

//Finding the lowest

double findLowest(double * arr)

{

double lowest = arr[0];

int i = 0 ;

for(i = 1; i < arraySize ; i++ )

{

if(arr[i] < lowest)

lowest = arr[i];

}

return lowest;

}

int main()

{

double * array = (double *) malloc(arraySize * sizeof(double));

takeInputGrades(array);

printf("Grades you entered: ");

int i = 0 ;

for(i = 0 ;i < arraySize ; i++)

{

printf("\n%.2f\n" , array[i]);

}

printf("\nAverage grade is : %.2f\n" , findAvg(array));

printf("Highest grade is : %.2f\n" , findHighest(array));

printf("Lowest grade is : %.2f\n" , findLowest(array));

free(array);

return 0;

}

The above code must be modified to use a custom struct to hold student's ID numbers and the percentage score for each item entered into the grade book. The program should accept the entry of ID numbers and percentage grades (0–100) until the user signals that he or she is done entering grades. The program should then print out the ID numbers and grades entered by the user, sorted by ID number.

Stai cercando di guadagnare dei soldi?

  • Stabilisci il tuo budget ed il tempo limite
  • Metti in rilievo la tua proposta
  • Fatti pagare per il tuo lavoro

Assumi Freelancer che hanno fatto un'offerta per questo progetto

    • Forbes
    • The New York Times
    • Time
    • Wall Street Journal
    • Times Online