Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this post there is 1 set of intructions 1 Program that ive created with most

ID: 3639564 • Letter: I

Question

In this post there is 1 set of intructions

1 Program that ive created with most algorithms

1 Program with the menu im supposed to creat

But i cant seem to put them together into a single program.


Use files to load data into parallel single dimensional arrays.
Display results on the screen for the user to view.
Write the results to an output file.

Write a menu driven program that offers 7 options to user:
Menu
A. Open files for Reading
B. Load Scores Data.
C. Load Names Data
D. Display Names, Scores, Average and Grade.
E. Open file for Output
F. Write Names, Scores, Average and Grade to File.
X. Exit
Notes:
Use a while loop with a menu display as the main program control structure.
A. Prompt and read file name from user for the scores data and the names data.
B. Load Scores Data into Scores Array
C. Load Names Data into Names Array
D. Display- First Name, Last Name, Score 1, Score 2, Score 3, Average and Grade.
E. Prompt and read output file name.
F. Write- Last Name, First Name, Score 1, Score 2, Score 3, Average and Grade to the output file.
X. Exit. Set the value of the Boolean variable to false.
General: Functionalize every process. Each function is to do only one thing. For example don’t write a function that performs calculations and does output. Break it into two functions.
Center your menu on the monitor. Use clear screen and pause to control program execution. Always return to the Menu after each menu choice.
Use meaningful identifier names and use variable naming conventions discussed in class.
Whenever possible write your functions so that they can be reused.
Write a value returning function “double average (int, int, int, int);”.

Write a value returning function “char grade (double);”;
Declare Global Constant RECORDS = 15;
Declare Global Constant SCORES = 3;

The Scores file will have three integer values per student (line). A maximum of 15 records
89 78 45
65 98 32
The Names file will have a first and last name value for each student (line). A maximum of 15 records and equal to the number of lines in the scores file.
George Washington
Abraham Lincoln

#include<iomanip> which will allow you to use the fixed, showpoint, setw() and setprecision() commands

// This is my program with main algorithms
// ****************************************************

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip> // Manipulates using cout << fixed << showpoint << setprecision(2);
using namespace std;

double Average(int);
char Grade(double);
int Sum(int, int);

// Build a data file with 15 rows of 5 data elements each
// You may not have use this in program #3
// Pay attention to how to declare, open and write to a file
// Global Constants
const int RECORDS = 15; // Controls Rows
const int SCORES = 2; // Controls Columns

int main()
{
int col;
int temp;
// int n1, // Never use these names n1, n2.
// n2;
int scores1[RECORDS],
scores2[RECORDS];
string last[RECORDS],
first[RECORDS];

// notice its now ofstream not just fstream
// input stream will be ifstream not fstream


ofstream newFile;
ifstream readFile;
string fileName = "C:\Users\a213.SAC.002\Desktop\demo.txt";
srand(3);


newFile.open(fileName.c_str());
// should check for successful open newFile.fail()

for(int index = 0; index < RECORDS;index++)
{
// Cant use if we want to control lower value of random number
// We will use the while loop below
// for(int col = 0;col < SCORES;col++)
// {
// newFile << rand() % 100 << " "; // Space in between numbers
// }

col = 0;
while (col < SCORES)
{
temp = rand() % 100;
if(temp >= 60)
{
newFile << temp << " ";
col++;
}
}
newFile << endl; // arrange in new lines
}
newFile.close();

// now we have a file called demo.txt with 15 records with two scores
// we now want to read the scores
// prime read= eliminates the double read of the last record
readFile.open(fileName.c_str());
col = 0;
readFile >> scores1[col] >> scores2[col];
while(!readFile.eof())
{
col++;
readFile >> scores1[col] >> scores2[col];

}
readFile.close();
// dump arrays to see if it works
// lcv1 moves down record..record...
cout << fixed << showpoint << setprecision(1);
for(int lcv1 = 0; lcv1 < RECORDS ; lcv1++)
{

cout << scores1[lcv1] << setw(6) << scores2[lcv1] << setw(9)
<< Average(Sum(scores1[lcv1],scores2[lcv1])) << endl;
}

// read names from file into arrays of type string

fileName = "C:\Users\a213.SAC.002\Desktop ames.txt";
readFile.open(fileName.c_str());
col = 0;

readFile >> last[col] >> first [col];
while (!readFile.eof())
{
col++;
readFile >> last[col] >> first[col];
}

readFile.close();

for(int lcv1 = 0; lcv1 < 3 ; lcv1++)
{
cout << setw(15) << last[lcv1] << ", " << first [lcv1] << " " << scores1[lcv1] << setw(6)
<< scores2[lcv1] << setw(9) << Average(Sum(scores1[lcv1],scores2[lcv1]))
<< setw(5) << Grade(Average(Sum(scores1[lcv1],scores2[lcv1])))
<< endl;
}

return 0;
}

double Average(int total)
{
return double(total)/SCORES; // Type Casting
}

char Grade(double score)
{
char grd;
if(score >= 90)
grd = 'A';
else if (score >= 70)
grd = 'C';
else if (score >= 60)
grd = 'D';
else
grd = 'F';

return grd;

}

int Sum(int n1, int n2)
{
return n1 + n2;

}

 

// ****************************************************** 

// This is my program for the menu.
// *-------------------------------------*
#include <iostream>
using namespace std;

char upcase(char);
void ProgramA(int);




int main()
{
char menuChoice;
bool userNotDone = true;
while (userNotDone)
{

// We can use these to check values of letters
// cout << int('a');
// cout << int('A');

system("cls");
cout << " ******* Menu ******* ";
cout << " A. Choice A ";
cout << " B. Choice B ";
cout << " C. Choice C ";
cout << " X. Choice X ";
cout << " Enter Menu Choice ==> ";
cin >> menuChoice;

switch (upcase(menuChoice))
{
case 'A': cout << "Picked A ";
system ("pause");
break;
case 'B': cout << "Picked B ";
system ("pause");
break;
case 'C': cout << "Picked C ";
system ("pause");
break;
case 'X': cout << "Exit";
userNotDone = false;
break;
default: cout << "Error Message "; // Function Call

}
}
return 0;
}



char upcase(char inComing)
{
if(inComing >= 'a' && inComing <= 'z') // lowercase starts at 65, uppercase at 97
inComing -= 32; // Prefered Syntax -= than -.

return inComing;
}

//************************************************



Explanation / Answer

I will give you useful guidelines to solve this problem and solve any such problems in future You are given a menu of operations to perform : A. Open files for Reading B. Load Scores Data. C. Load Names Data D. Display Names, Scores, Average and Grade. E. Open file for Output F. Write Names, Scores, Average and Grade to File. X. Exit What you need to do is for every operation given in the menu list, create one single function for each menu operations in your first programs. So you have the following functions : void openfileread(FILE *fptr, char *filename); // to open the file for read load_score_data(....); load_names_data(...); diplayresults(.....); openfilewrite(....); writeresults(.....); Pass appropriate parameters to the functions and return the proper values which are required. Write all the code for doing the tasks only in these functions. After doing the above, things become too easy. In your second program, I am just showing the switch-case part as only change needs to be done there. In all the cases just give the call to appropriate functions. Include the code of the functions from the first program on top of this program(or you can create a static library) Also declare the variable to be used to pass to these functions in the second program on the beggining of main. Initialize their values appropriately(do it within the switch case for each menu operations before giving call to their functions). switch (upcase(menuChoice)) { case 'A': cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote