Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programming help, I need help seeing how to turn each loop into function. Attach pics have more info and the following is the code

C programming help, I need help seeing how to turn each loop into function. Attach pics have more info and the following is the code were changing around.
#include int main (void) { //2D array for grade int grade [6][7]; //1D array for grade average double stuAvg[6]; //1D array for lab average double labAvg[7]; //1D array for sorting int sortedGrade[42]; //Declare variables for loops int i = 0, j = 0, k = 0; //Declare variables for sort int temp, minPos; //Calculation variable double total = 0.0; //Read in input with a scanf while(i sortedGrade[j]) minPos = j; } if(minPos != i) { temp = sortedGrade[i]; sortedGrade[i] = sortedGrade[minPos]; sortedGrade[minPos] = temp; } } printf(" "); printf(" "); //Display sorted grades for(k = 0; k
image text in transcribed
image text in transcribed
image text in transcribed
* Fant. Pod.eypes shald por the isp of year file befwe olies) should he prceded with a comment that includles a brie desrition o the function and also shows the iputs and outputs of the fusction (see eample code aove Always indent your code in a recadable waySome formatting cxamplos maybe found here Don' forgt to usethe -Wal1 flag when compiling tor esample go-Mal3 3ab0 Your program should work according to this algorithm declre 2-D array using Rdefinod values for each dimonsion 2 call getGrades 0 3 call printGrades call printAvgs from withis studentAngs fonction) call labg 6. call sortGrades call peintSorted) em wihin soetGeades finction) The maia funtion becomes shot and concise with 7 ines of eede inclading the dec lration of the 2 D anay, the abeve 5 function calls, and the netun statemem Sieps for conventing lab 9 logs to fiunctions for lab 10 L For this peogram, the mmber of sdets and the mumber of labs should be define nanmes and unad oe the dimesions of the 2-D aray and leap indes variables indcad of hand-oading those valus. You cn e the nama STUDENTS and LABS 2. The fot liep meialized the 2-D anay alled grades should be moved intoindie called getGrases o. Th functm shouldtake inong argument the 2-Damay, and it won't be retning ything 3. You should have a fancim allad pr itGs adesO the 2-D amay, This fanction will take in one argumant: the 2-D amay and won't rture anything This fanction will contain the nesto for loop that you have from lab 9 that printed the gradea. A this s call this fundtion from withis main)Compille and run that will be callal .ny tinne you want to pr values th The loop in main) that computos he avcrage for cach stalent should be mned to a fiunction callad studentAvgs. This funstion will take in the 2 D amay as an argument and won nturm anything Wie this fnction call the printavgs 13 function (which is the net stap 5. You should have a fnmn called printAvgs o th will be called to-the averges fanction will take in three anguments: the sine efthe 1-D aray sent in (so it can be usad for any 1-D aray oan sian and tel-Damayoontanng teavdrages to be printed, and a string Odar amyentanngthe ing corresponding to which amay iis:"Shalan-"Lab" That string will be used the pm statmn aion will ne reture anything Compile and the 1-D amay. This 6 Similar to sp 4 aove, the average of each lab should be computed in a separate fiunction callod abavgs whidh will take in the 2-D amay as an arpumen and won't edum anything Within this tin eall the printavgsfunction to print thoe avarapes Compile and ren The soning will aho be done in a saparate function, called sortGrades As with the other fantion the 2D Wihin this liunction yeu s array will be for holhngthe uorted array From withuaths sort Grades()function air the loc that the artay, call he prineser ted faction sending B,the sue and the local any varuble. 4the soned copy ofthe itay). This is a thront functionan the other pr int Avgs( ) fnction because they havea dtleron mber of apnem should declae a y as a local vanable te ue Your outgun for the enine program should look the same as lab 9's outpa Student 2: 78 93 709 985 Student 3 10090 7278 Student 4 98 100 5 6 28 89 Student 22 5 725 75 4 BB

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2000 Database Design

Authors: Louis Davidson

1st Edition

1861004761, 978-1861004765

More Books

Students also viewed these Databases questions

Question

if f(t) = t cos ()u (t-1) Find F (s)

Answered: 1 week ago