Need this in C++. Its looking long but the functions are quite short. I am just
ID: 3857470 • Letter: N
Question
Need this in C++. Its looking long but the functions are quite short. I am just not fluent in c++.
This problem is divided into eight parts. Your main program should make a call to these eight functions, passing the necessary parameters and getting the necessary return values. You must provide functions with the given names and parameters. The names of any other supporting functions are named at your discretion. The names ofthe supporting functions that you implement should be reflective of the function they perform. You will not take any user inputs in the functions in your Assignment5.cpp file. The problem statement is designed in a way that all the inputs to the functions are being passed from your main function. Secondly, you will not be printing any values in these functions. You need to evaluate the correctness of your implementation by writing code in your main program and validating the return values from these function. In this assignment you will make use of arrays as your data structure to store values and looping should be preferably done using for loops NOTE: Treat every function as an independent function, wherein each function can take a different array as an input. Homework Problem: There are eight parts to the problem, following is the step by step description of the same. Part 1 Function call to initialize a given array with the given value. void fillArray(int data0,int size, int value) The fillArray0 function will take in three arguments, an array of integers, the size of the array and an integer value with which the array has to be initialized. You should pass the reference of your integer array that you declare in your main function to this function. The function should fill the entire array with the given value. The function does not return any value. Tip To test the validity of the function you can print the values of the array in your main function after the function call to check if the entire array has been initialized correctly. You can follow similar validation s for all the other functions.Explanation / Answer
#include <iostream>
#include <vector>
using namespace std;
void fillArray(int data[], int size, int value){
for(int i=0; i<size; i++){
data[i] = value;
}
}
float getAverageScores(float scores[],int size){
float sum = 0;
for(int i=0; i<size; i++){
sum = sum + scores[i];
}
return sum/size;
}
void calculateGrades(float scores[], char grades[], int size){
for(int i=0;i<size; i++){
if(scores[i]>=90){
grades[i] = 'A';
}
else if(scores[i]>=80 && scores[i]<90){
grades[i] = 'B';
}
else if(scores[i]>=70 && scores[i]<80){
grades[i] = 'C';
}
else if(scores[i]>=60 && scores[i]<70){
grades[i] = 'D';
}
else{
grades[i] = 'F';
}
}
}
float getMedian(float scores[],int size){
float median;
int n = size/2;
if(size % 2 == 0){
median = (scores[n]+scores[n-1] )/2;
}
else{
median = scores[n];
}
return median;
}
float getMinScores(float scores[],int size){
float minScore = scores[0];
for(int i=0; i<size; i++){
if(minScore > scores[i]){
minScore = scores[i];
}
}
return minScore;
}
float getMaxScores(float scores[],int size){
float maxScore = scores[0];
for(int i=0; i<size; i++){
if(maxScore < scores[i]){
maxScore = scores[i];
}
}
return maxScore;
}
int countGrade(char grades[],char grade, int size){
int count = 0;
for(int i=0; i<size; i++){
if(grades[i]==grade){
count++;
}
}
return count;
}
void sortScores(float scores[],int size){
float temp = 0;
for(int i=0; i < size; i++){
for(int j=1; j < (size-i); j++){
if(scores[j-1] > scores[j]){
//swap the elements!
temp = scores[j-1];
scores[j-1] = scores[j];
scores[j] = temp;
}
}
}
}
int main()
{
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.