Question

In: Computer Science

WITHOUT USING POINTERS. This is C programming. I am writing a program which should calculate standard...

WITHOUT USING POINTERS. This is C programming. I am writing a program which should calculate standard deviation of an array of exam scores and then add the standard deviation to each array element. It should print the original array, the standard deviation, and the new rounded adjusted array. I included my question as a comment in the line of code that is giving me an issue. (Removing the a from E-x-a-m as Chegg doesn't allow the word.)

#include <stdio.h>
#include <math.h>


float calcstddev(float exmgrades[], int size)
{
   float sum =0.0;
   float mean;
   int temp;
   float variance;
   float stddev;
   float difference;


   for (temp=0;temp<size;++temp)
   {
       sum+=exmgrades[temp];
   }
   mean = sum/size;
   for (temp=0;temp<size;++temp)
   {
   stddev+=pow(exmgrades[temp]-mean,2);
   }
   stddev/=size;
   stddev=sqrt(stddev);
   return stddev;
}


float adjustscores(float exmgrades[],int size)
{
   float stddev=calcstddev(exmgrades,7);
   int temp=0;
   float adjustedscores[size];
  
   for(temp=0;temp<size;++temp)
   {
       adjustedscores[temp]+=exmgrades[temp]+stddev;
   }
   return adjustedscores; //////HERE is the line that gives me an error. It states:[Error] incompatible types when returning type 'float *' but 'float' was expected.    If I remove this line, my output for the adjusted array elements is .0f, so the data isn't passed to main. What should I do here? ///////////////////
}


int main()
{
   float exmgrades[]={90,95,90,82,80,87,92};
   float stddev=calcstddev(exmgrades,7);
   int size;
   int arrayprint;
   float adjustedscores[size];

   printf("The exm scores are: ");
   for (arrayprint = 0; arrayprint < 7; arrayprint++)
   {
    printf("%.0f ", exmgrades[arrayprint]);
   }


   printf("\nThe standard deviation is %.4f", stddev);
   printf("\nThe adjusted scores are: ");
   for (arrayprint =0; arrayprint <7; arrayprint++)
   {
    printf(".0f", adjustedscores[arrayprint]);
   }


}

Solutions

Expert Solution

Complete Working Code

#include <stdio.h>
#include <math.h>


float calcstddev(float exmgrades[], int size)
{
   float sum =0.0;
   float mean;
   int temp;
   float variance;
   float stddev;
   float difference;


   for (temp=0;temp<size;++temp)
   {
       sum+=exmgrades[temp];
   }
   
   mean = sum/size;
   
   for (temp=0;temp<size;++temp)
   {
                stddev+=pow(exmgrades[temp]-mean,2);
   }
   
   stddev/=size;
   stddev=sqrt(stddev);
   return stddev;
}


float adjustscores(float exmgrades[],int size)
{
   float stddev=calcstddev(exmgrades,7);
   int temp=0;
   float adjustedscores[size];
  
   for(temp=0;temp<size;temp++)
   {
           adjustedscores[temp] = 0; // change 3: initializing with 0, as it was giving garbage value
       adjustedscores[temp]+= exmgrades[temp] + stddev;
   }
   
   //change 2: printing the adjusted array in the function itself
   printf("\nThe adjusted scores are: ");
   
   for(temp=0; temp <size; temp++)
   {
                printf("%0.0f  ", adjustedscores[temp]);
   }
}


int main()
{
   float exmgrades[]={90,95,90,82,80,87,92};
   float stddev=calcstddev(exmgrades,7);
   int size;
   int arrayprint;
   float adjustedscores[size];

   printf("The exm scores are: ");
   
   for (arrayprint = 0; arrayprint < 7; arrayprint++)
   {
                printf("%0.0f ", exmgrades[arrayprint]);
   }


   printf("\nThe standard deviation is %.4f", stddev);
   
   adjustscores(exmgrades, 7); // change 1: added function call
   
}

Output Screenshot

I have made few changes in the code that has been mentioned in the code as comments:

change 1: Function call added to the main function

change 2: Function will not return the value, printing the adjusted array in the function itself.

change 3:initialize the elements of adjusted array, as it was giving the garbage value.

Please copy and paste the code and execute in your IDE to see the output.


Related Solutions

C Programming Run Length Encoder (Compression). I am writing a program that takes an image (from...
C Programming Run Length Encoder (Compression). I am writing a program that takes an image (from a text file) and looks for patterns of 2 or more duplicate values. The program should replace these values with the following pattern:  2 such characters followed by an Integer ( which represents number of occurrences of each character), followed by an asterisk. For example say the input of the non-compressed image was: ,,,,)H 7. i.e. it consists of four commas, one closed bracket, the...
I am writing a shell program in C++, to run this program I would run it...
I am writing a shell program in C++, to run this program I would run it in terminal like the following: ./a.out "command1" "command2" using the execv function how to execute command 1 and 2 if they are stored in argv[1] and argv[2] of the main function?
I am Writing a C-Program to read and write files. but none of my code is...
I am Writing a C-Program to read and write files. but none of my code is working like it should be. Please fix all code and supply output response. Please try to use existing code and code in comments. But if needed change any code that needs to be changed. Thank you in advance //agelink.c //maintains list of agents //uses linked list #include <stdio.h> #include <stdlib.h> #define TRUE 1 void listall(void); void newname(void); void rfile(void); void wfile(void); struct personnel {...
this program is to be done in c language. Using Pointers Create a program pointerTester.c to...
this program is to be done in c language. Using Pointers Create a program pointerTester.c to experiment with pointers. Implement the following steps one by one in your program: YOU NEED TO ANSWER QUESTION Use printf to print your answers at the end(after 12). 1. Declare three integer variables a, b and c. Initialize them to 0, 100 and 225, respectively. 2. Print the value of each variable and its address. 3. Add the following declaration to your code: int...
You are using ONLY Programming Language C for this: In this program you will calculate the...
You are using ONLY Programming Language C for this: In this program you will calculate the average of x students’ grades (grades will be stored in an array). Here are some guidelines to follow to help you out: 1. In your program, be sure to ask the user for the number of students that are in the class. The number will help in declaring your array. 2. Use the function to scan the grades of the array. To say another...
I need to write a C++ program that appends "not" into the string without using the...
I need to write a C++ program that appends "not" into the string without using the append method or any standard libraries. It should return the string if there isn't an "is" in it. Examples: is is = is not is not This is me = This is not me What is yellow? = What is not yellow? The sky is pink = The sky is not pink isis = isis What happened to you? = What happened to you?
I am trying to write code for a program in Visual Studo using Visual Basic programming...
I am trying to write code for a program in Visual Studo using Visual Basic programming language that computes the factorial of an entered number by using a For Loop. My problem is that it keeps re-setting the variable for Factorial. Below is my code if anyone can help. I want it to multiply the given number by that number - 1, then continuing to do so until it hits zero without multiplying by zero. Private Sub BtnCalculate_Click(sender As Object,...
TCP client and server using C programming I am having trouble on how to read in...
TCP client and server using C programming I am having trouble on how to read in the IP adress and port number from the terminal Example: Enter IP address: 127.0.0.1 Enter Port Number: 8000 in both client and server code. How do can I make I can assign the Ip address and port number using the example above. the error I get is that the client couldn't connect with the server whenever i get the port number from the user...
In C programming, I am trying to search for the names of people that in this...
In C programming, I am trying to search for the names of people that in this DOISigned.txt file, however I am having trouble getting the first and last names of the multiple people named john, my current code only searches for John once and then it terminates,here is my current code #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> #include <stdlib.h> #define BUF_SIZE 0x3000 char buf[BUF_SIZE]; int main() {    char* inputFile = "DOISigners.txt";    FILE* fp;    fp = fopen(inputFile, "r");...
Use any C program without using PTHREADS calculate time taken to execute program. Write same program...
Use any C program without using PTHREADS calculate time taken to execute program. Write same program of question 1 using PTHREADS. Calculate time taken to execute program.(1 mark) Identify data races in above program and explain why this situation occurred with an example (1 mark) Rewrite the code to avoid data races should use any of the THREE techniques.(1.5 marks) please I need the c code.. critical section mutex solution semaphore functions Barriers Read-Write Locks Run program using 1, 2,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT