Question

Hello, I have written a code that I now need to make changes so that arrays...

Hello, I have written a code that I now need to make changes so that arrays are transferred to the functions as pointer variable. Below is my code I already have.

#include<iostream>
#include<string>
#include<iomanip>

using namespace std;


//functions prototypes
void getData(string id[], int correct[], int NUM_STUDENT);
void calculate(int correct[], int incorrect[], int score[], int NUM_STUDENT);
double average(int score[], int NUM_STUDENT);
void Display(string id[], int correct[], int incorrect[], int score[], double average, int NUM_STUDENT);
int findHigh(string id[], int score[], int NUM_STUDENT);
//declaring constants
const int NUM_STUDENT = 4;
const int NUM_Q = 50;
//main
int main()
{
   //array declaration
   int correct[NUM_STUDENT], incorrect[NUM_STUDENT], score[NUM_STUDENT];
   string id[NUM_STUDENT];

   //function calls
   getData(id, correct, NUM_STUDENT);
   calculate(correct, incorrect, score, NUM_STUDENT);

   double avg = average(score, NUM_STUDENT);

   Display(id, correct, incorrect, score, avg, NUM_STUDENT);

   int high = findHigh(id, score, NUM_STUDENT);
   cout << "Highest Test Score: " << high;
   cout << endl;

   system("pause");
   return 0;
}

//method getData
void getData(string id[], int correct[], int NUM_STUDENT)
{
   for (int i = 0; i < NUM_STUDENT; i++)
   {
       //reading user input
       cout << "Student's ID\t\t\t: ";
       cin >> id[i];
       cout << "Number of correct answers\t: ";
       cin >> correct[i];
       cout << endl;
   }
}


void calculate(int correct[], int incorrect[], int score[], int NUM_STUDENT)
{
   for (int i = 0; i < NUM_STUDENT; i++)
   {
       //calculating score
       incorrect[i] = NUM_Q - correct[i];
       score[i] = 2 * correct[i];
   }
}

double average(int score[], int NUM_STUDENT)
{
   double sum = 0.0;
   for (int i = 0; i < NUM_STUDENT; i++)
   {
       sum += score[i];
   }

   return sum / NUM_STUDENT;
}


void Display(string id[], int correct[], int incorrect[], int score[], double average, int NUM_STUDENT)
{
   system("cls");
   cout << "ID\t\tCorrect Answers\t\tIncorrect Answers\tScore\n\n";
   for (int i = 0; i < NUM_STUDENT; i++)
   {
       cout << id[i] << "\t\t\t" << correct[i] << "\t\t\t" << incorrect[i] << "\t\t " << score[i] << endl;
   }

   cout << "\n\nSummary:\n\n";
   cout << "Test Score Average: " << fixed << showpoint << setprecision(2) << average << endl;
}

int findHigh(string id[], int score[], int NUM_STUDENT)
{
   int max = score[0];
   for (int i = 1; i < NUM_STUDENT; i++)
   {
       if (max < score[i])
           max = score[i];
   }

   return max;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<string>
#include<iomanip>

using namespace std;


//functions prototypes
void getData(string *id, int *correct, int NUM_STUDENT);
void calculate(int *correct, int *incorrect, int *score, int NUM_STUDENT);
double average(int *score, int NUM_STUDENT);
void Display(string *id, int *correct, int *incorrect, int *score, double average, int NUM_STUDENT);
int findHigh(string *id, int *score, int NUM_STUDENT);
//declaring constants
const int NUM_STUDENT = 4;
const int NUM_Q = 50;
//main
int main()
{
   //array declaration
   int correct[NUM_STUDENT], incorrect[NUM_STUDENT], score[NUM_STUDENT];
   string id[NUM_STUDENT];

   //function calls
   getData(id, correct, NUM_STUDENT);
   calculate(correct, incorrect, score, NUM_STUDENT);

   double avg = average(score, NUM_STUDENT);

   Display(id, correct, incorrect, score, avg, NUM_STUDENT);

   int high = findHigh(id, score, NUM_STUDENT);
   cout << "Highest Test Score: " << high;
   cout << endl;

   system("pause");
   return 0;
}

//method getData
void getData(string *id, int *correct, int NUM_STUDENT)
{
   for (int i = 0; i < NUM_STUDENT; i++)
   {
       //reading user input
       cout << "Student's ID\t\t\t: ";
       cin >> *(id+i);
       cout << "Number of correct answers\t: ";
       cin >> *(correct+i);
       cout << endl;
   }
}


void calculate(int *correct, int *incorrect, int *score, int NUM_STUDENT)
{
   for (int i = 0; i < NUM_STUDENT; i++)
   {
       //calculating score
       *(incorrect+i) = NUM_Q - *(correct+i);
       *(score+i) = 2 * (*(correct+i));
   }
}

double average(int *score, int NUM_STUDENT)
{
   double sum = 0.0;
   for (int i = 0; i < NUM_STUDENT; i++)
   {
       sum += *(score+i);
   }

   return sum / NUM_STUDENT;
}


void Display(string *id, int *correct, int *incorrect, int *score, double average, int NUM_STUDENT)
{
   system("cls");
   cout << "ID\t\tCorrect Answers\t\tIncorrect Answers\tScore\n\n";
   for (int i = 0; i < NUM_STUDENT; i++)
   {
       cout << *(id+i) << "\t\t\t" << *(correct+i) << "\t\t\t" << *(incorrect+i) << "\t\t " << *(score+i) << endl;
   }

   cout << "\n\nSummary:\n\n";
   cout << "Test Score Average: " << fixed << showpoint << setprecision(2) << average << endl;
}

int findHigh(string *id, int *score, int NUM_STUDENT)
{
   int max = *score;
   for (int i = 1; i < NUM_STUDENT; i++)
   {
       if (max < *(score+i))
           max = *(score+i);
   }

   return max;
}

Add a comment
Know the answer?
Add Answer to:
Hello, I have written a code that I now need to make changes so that arrays...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Am I getting this error because i declared 'n' as an int, and then asking it...

    Am I getting this error because i declared 'n' as an int, and then asking it to make it a double? This is the coude: #include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <algorithm> #include <vector> using namespace std; void sort(double grades[], int size); char calGrade(double); int main() {    int n;    double avg, sum = 0;;    string in_file, out_file;    cout << "Please enter the name of the input file: ";    cin >> in_file;   ...

  • c++ programming : everything is done, except when you enter ("a" ) in "F" option ,...

    c++ programming : everything is done, except when you enter ("a" ) in "F" option , it does not work. here is the program. #include <iostream> #include <string> #include <bits/stdc++.h> #include <iomanip> #include <fstream> using namespace std; #define MAX 1000 class Inventory { private: long itemId; string itemName; int numberOfItems; double buyingPrice; double sellingPrice; double storageFees; public: void setItemId(long id) { itemId = id; } long getItemId() { return itemId; } void setItemName(string name) { itemName = name; } string...

  • Please help fix my code C++, I get 2 errors when running. The code should be...

    Please help fix my code C++, I get 2 errors when running. The code should be able to open this file: labdata.txt Pallet PAG PAG45982IB 737 4978 OAK Container AYF AYF23409AA 737 2209 LAS Container AAA AAA89023DL 737 5932 DFW Here is my code: #include <iostream> #include <string> #include <fstream> #include <vector> #include <cstdlib> #include <iomanip> using namespace std; const int MAXLOAD737 = 46000; const int MAXLOAD767 = 116000; class Cargo { protected: string uldtype; string abbreviation; string uldid; int...

  • I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using...

    I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using namespace std; int NumOfEmployees(); int TotDaysAbsent(int); double AverageAbsent(int, int); int main() {         cout << endl << "Calculate the average number of days a company's employees are absent." << endl << endl;      int numOfEmployees = NumOfEmployees();         TotDaysAbsent(numOfEmployees);    return 0; } int NumOfEmployees() {    int numOfEmployees = 0;     cout << "Please enter the number of employees in the company: ";         cin >> numOfEmployees;     while(numOfEmployees <= 0)     {            ...

  • Hello I have a question. I would like to check if the code follows this requirement....

    Hello I have a question. I would like to check if the code follows this requirement. Rectangle.h - A complete Rectangle Class including both declaration and definition appRectangle,cpp separate in two different files the class definition and implementation Code: rectangle.h // Rectangle class declaration. class Rectangle { private: double width; double length; public: void setWidth(double); void setLength(double); double getWidth() const; double getLength() const; double getArea() const; }; //************************************************** // setWidth assigns a value to the width member. * //************************************************** void...

  • Today assignment , find the errors in this code and fixed them. Please I need help...

    Today assignment , find the errors in this code and fixed them. Please I need help with find the errors and how ro fixed them. #include <iostream> #include <cstring> #include <iomanip> using namespace std; const int MAX_CHAR = 100; const int MIN_A = 90; const int MIN_B = 80; const int MIN_C = 70; double getAvg(); char determineGrade(double); void printMsg(char grade); int main() { double score; char grade; char msg[MAX_CHAR]; strcpy(msg, "Excellent!"); strcpy(msg, "Good job!"); strcpy(msg, "You've passed!"); strcpy(msg, "Need...

  • Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string;...

    Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string; class Account { public: Account(); Account(string, double); void deposit(double); bool withdraw(double); string getName() const; double getBalance() const; private: string name; double balance; }; #endif ////////////////////////////////////////////// //AccountManager.hpp #ifndef _ACCOUNT_MANAGER_HPP_ #define _ACCOUNT_MANAGER_HPP_ #include "Account.hpp" #include <string> using std::string; class AccountManager { public: AccountManager(); AccountManager(const AccountManager&); //copy constructor void open(string); void close(string); void depositByName(string,double); bool withdrawByName(string,double); double getBalanceByName(string); Account getAccountByName(string); void openSuperVipAccount(Account&); void closeSuperVipAccount(); bool getBalanceOfSuperVipAccount(double&) const;...

  • I have a C++ code that lets me enter, display and delete a student record. I...

    I have a C++ code that lets me enter, display and delete a student record. I need to implement a function that prints the average grade score of the students I input. Below is my code and a picture of how my code looks right now. #include<iostream> #include<stdlib.h> using namespace std; //Node Declaration struct node {    string name;    string id;    int score;    node *next;   }; //List class class list {        private:        //head...

  • I have 2 issues with the C++ code below. The biggest concern is that the wrong...

    I have 2 issues with the C++ code below. The biggest concern is that the wrong file name input does not give out the "file cannot be opened!!" message that it is coded to do. What am I missing for this to happen correctly? The second is that the range outputs are right except the last one is bigger than the rest so it will not output 175-200, it outputs 175-199. What can be done about it? #include <iostream> #include...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT