
Concept explainers
CODE to Copy & Paste
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void readStudData(ifstream &rss, int scores[], int id[], int &count, bool &tooMany);
float mean(int scores[], int count);
void printTable(int score[], int ID[], int count);
void printGrade(int oneScore, float average);
// Only accept MAX_SIZE entries, this will be the size of our arrays
const int MAX_SIZE = 10;
int main()
{
// variables. Need to create two int arrays: scores and ID.
// Need to create one int: count. Need to create one bool: tooMany
int scores[MAX_SIZE];
int ID[MAX_SIZE];
int count;
bool tooMany;
// Call readStudData to read data from the file that was opened above
// inFile is the name of the file opened
ifstream inFile;
inFile.open("scores.txt");
readStudData(inFile, scores, ID, count, tooMany);
// Don't forget to close the file
inFile.close();
// If there are more than MAX_SIZE records in the file, then tooMany should be
// set to true. We need to warn the user that not all the records were used
if( tooMany ) cout << "\nWarning! Some data is missing\n";
// Print the data
printTable(scores, ID, count);
cout << endl;
system("Pause");
return 0;
}
void readStudData(ifstream &rss, int scores[], int id[], int &count, bool &tooMany)
{
// Set tooMany to false and count to 0
tooMany = false;
count = 0;
while(!rss.eof())
{
if(count == MAX_SIZE) break;
rss >> id[count] >> scores[count];
count++;
}
// Determine if we have too many records in the file
if( !rss.eof() && count == MAX_SIZE ) tooMany = true;
}
float mean(int scores[], int count)
{
// Store the sum of the scores here
int sum = 0;
// Loop through and accumulate the scores from the array
for(int i = 0; i < count; i++)
{
sum += scores[i];
}
// Return the average
return (float)sum/count;
}
void printTable(int score[], int ID[], int count)
{
// Need the average
float average = mean(score, count);
// Display the average to the user
cout << "Average: " << average << endl;
// Display the header for the table
cout << "ID\t" << "Score\t" << "Grade" << endl;
for(int i = 0; i < count; i++)
{
cout << ID[i] << '\t' << score[i] << '\t';
printGrade(score[i], average);
}
}
void printGrade(int oneScore, float average)
{
if(oneScore < average + 10 && oneScore > average - 10) cout << "Satisfactory\n";
else if(oneScore > average + 10) cout << "Outstanding\n";
else cout << "Unsatisfactory\n";
}
TASK
Redo using a struct to store each student’s data and an array of structs to store the whole class. The struct should have data members for id, score, and grade.

C++ Language
Python is slower than C++ because C++ is statically typed, which speeds up code compilation. Python employs the interpreter, which slows down compilation, and it supports dynamic typing, which makes it slower than C++.
Step by stepSolved in 3 steps with 1 images

- C PROGRAMMING Instructions: Use the code template below to implement the length() and reverse() functions into the main() /* This program will create a string which is the reverse of an original string using pointers. * Performs string handling, manipulates pointers, passes pointers to functions. */ #include <stdio.h>#include <stdlib.h> int length( ){ while(str1[len++] != '\0'); // Calculate length of string len--; // Remove the null character len--; // Array index start from 0 to (length -1) return ; } void reverse( ){ while (counter < len) { i = str1[counter]; str1[counter] = str1[len]; str1[len] = i; counter++; len--; } return ;} int main (){ char str1[41]; // String to be Reversed printf("Enter some text (No spaces and 40 characters max): "); scanf("%40s", str2); printf("Reversed string: %s\n", str1); return 0;}arrow_forwardCoorect the Following C++ code: #include <bits/stdc++.h>#include <iostream>#include <fstream>#include <string>#include <cctype> using namespace std; // Function to print available currencies for exchangevoid printCurrencies() { cout << "Available currencies for exchange: " << endl; cout << "SAR --> Saudi Arabia Riyal" << endl; cout << "KWD --> Kuwaiti Dinar" << endl; cout << "QAR --> Qatar Riyal" << endl; cout << "AED --> United Arab Emirates Dirham" << endl; cout << "BHD --> Bahraini Dinar" << endl; cout << "OMR --> Omani Rial" << endl;} // Function to convert currencydouble convertCurrency(string fromCurrency, string toCurrency, double amount) { ifstream exchangeRateFile("ExchangeRate.txt"); // Open file for reading string line; double desiredRate=0; while (getline(exchangeRateFile, line)) { // Read file…arrow_forwardC++ programming task. main.cc file: #include <iostream>#include <map>#include <vector> #include "plane.h" int main() { std::vector<double> weights{3.2, 4.7, 2.1, 5.5, 9.8, 7.4, 1.6, 9.3}; std::cout << "Printing out all the weights: " << std::endl; // ======= YOUR CODE HERE ======== // 1. Using an iterator, print out all the elements in // the weights vector on one line, separated by spaces. // Hint: see the README for the for loop syntax using // an iterator, .begin(), and .end() // ========================== std::cout << std::endl; std::map<std::string, std::string> abbrevs{{"AL", "Alabama"}, {"CA", "California"}, {"GA", "Georgia"}, {"TX", "Texas"}}; std::map<std::string, double> populations{ {"CA", 39.2}, {"GA", 10.8}, {"AL", 5.1}, {"TX", 29.5}}; std::cout <<…arrow_forward
- C++ Code dynamicarray.h and dynamicarray.cpparrow_forwardCode in C Code in the file IO: /************************************************************* This program prints a degree-to-radian table using a for- loop structure. The results are printed to a file and the the screen. *************************************************************/ #include <stdio.h> #define PI 3.141593 #define FILENAME "tableD2R.dat" int main(void) { /* Declare variables. */ double radians; FILE *fileout; /* Open file. */ fileout = fopen(FILENAME,"w"); if (fileout == NULL) printf("Error opening input file. \n"); else { /* Print radians and degrees in a loop. */ printf("Degrees to Radians \n"); for (int degrees=0; degrees<=360; degrees+=10) { radians = degrees*PI/180; printf("%6i %9.6f \n",degrees,radians); fprintf(fileout,"%6i %9.6f \n",degrees,radians); } /* Exit program. */ }arrow_forward#include <iostream>#include <pthread.h>#include <stdlib.h> #define TOTAL_THREADS 4 int count;pthread_mutex_t the_mutex; // phread mutex variable - initialize here if using the initializer macro void* myFunction(void* arg){int actual_arg = *((int*) arg);for(unsigned int i = 0; i < 10; ++i) {// TODO:// Use a Pthread mutex to control// access to the critical region. // Beginning of the critical regioncount++;std::cout << "Thread #" << actual_arg << " count = " << count << std::endl; // End of the critical region// TODO:// Relinquish access to the Pthread mutex// since critical region is complete. // Random wait - This code is just to ensure that the threads// show data sharing problemsint max = rand() % 100000;for (int x = 0; x < max; x++);// End of random wait code}pthread_exit(NULL);} int main(){int rc[TOTAL_THREADS];pthread_t ids[TOTAL_THREADS];int args[TOTAL_THREADS];// TODO: Initialize the pthread mutex here if using the…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





