Please help!! I am supposed to write a program in C++ about student & grades.
Needs to have two functions that sorts students letter grade, and another one to sort Students name in your student’s record project. Remember, to add necessary parameters and declaration in main to call each function properly. Order of functions call are as follow
THIS IS WHAT I HAVE SO FAR:
(im missing the sorting & search functions, [i need to have a header function and then call them from the main)
#include
#include
#include
#include
#include
using namespace std;
const int row = 10;
const int col = 7;
ifstream name;
ifstream grade;
ofstream out;
void readData(string stname[row], int stgrade[row][col]);
void stsum(int stgrade[row][col], int total[row]);
void staverage(int total[row], double average[row]);
void stlettergrade(double average[row],char ltrgrade[row]);
void displayData(string stname[row], int stgrade[row][col], int
total[row], double staverage[row], char ltrgrade[row]);
int main()
{
int STG[row][col] = { {0},{0} };
string STN[row] = {};
int STT[row] = { 0 };
double STA[row] = { 0.0 };
char STLG[row] = {};
readData(STN,STG);
stsum(STG, STT);
staverage(STT, STA);
stlettergrade(STA, STLG);
displayData(STN, STG, STT,STA, STLG);
name.close();
grade.close();
out.close();
system("pause");
return 0;
}
//========================Function to Read
Data===================================
void readData(string stname[row], int stgrade[row][col])
{
name.open("Name.txt");
grade.open("Grade.txt");
int r, c;
for (r = 0; r < row; r++)
{
getline(name, stname[r]);
for (c = 0; c < col; c++)
{
grade >>
stgrade[r][c];
}
}
}
//==================Funtion for Grade
Total======================================
void stsum(int stgrade[row][col], int total[row])
{
int r, c;
for (r = 0; r < row; r++)
{
for (c = 0; c
< col; c++)
total[r] = total[r] + stgrade [r][c];
}
}
//=========================Function for
Average=================================
void staverage(int total[row], double average[row])
{
int r, c;
for (r=0;r {
for (c = 0; c < col; c++)
average[r] =
static_cast(total[r]/col);
}
}
//========================Function for Letter
Grade==============================
void stlettergrade(double average[row], char ltrgrade[row])
{
int r;
for (r = 0; r < row; r++)
{
if (average[r]
>= 90)
ltrgrade[r] = 'A';
else if
(average[r] >= 80)
ltrgrade[r] = 'B';
else if
(average[r] >= 70)
ltrgrade[r] = 'C';
else if
(average[r] >= 60)
ltrgrade[r] = 'D';
else
ltrgrade[r] = 'F';
}
}
//=============================Function to Display
Data=======================
void displayData(string stname[row], int stgrade[row][col], int
total[row], double staverage [row], char ltrgrade[row])
{
out.open("Results.txt");
int r, c;
for (r = 0; r < row; r++)
{
out <<
stname[r] << setw(3);
for (c = 0; c
< col; c++)
out << setw(5) <<
stgrade[r][c];
out <<
setw(5) << total[r]<< setw(5) <<
staverage[r]<< setw(5) << ltrgrade[r] <<
endl;
}
}
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdlib>
using namespace std;
const int row = 10;
const int col = 7;
ifstream name;
ifstream grade;
ofstream out;
void readData(string stname[row], int stgrade[row][col]);
void stsum(int stgrade[row][col], int total[row]);
void staverage(int total[row], double average[row]);
void stlettergrade(double average[row],char ltrgrade[row]);
void displayData(string stname[row], int stgrade[row][col], int total[row], double staverage[row], char ltrgrade[row]);
// sort functions
void sortByLetterGrade(string stname[row], int stgrade[row][col], int total[row], double staverage[row], char ltrgrade[row]);
void sortByName(string stname[row], int stgrade[row][col], int total[row], double staverage[row], char ltrgrade[row]);
int main() {
int STG[row][col] = { {0},{0} };
string STN[row] = {};
int STT[row] = { 0 };
double STA[row] = { 0.0 };
char STLG[row] = {};
readData(STN,STG); // Read Data
stsum(STG, STT); // Find Total
staverage(STT, STA); // Find average
stlettergrade(STA, STLG); // Find letter grade
displayData(STN, STG, STT,STA, STLG); // Call display function
sortByLetterGrade(STN, STG, STT,STA, STLG); // Call sort letter grade function
displayData(STN, STG, STT,STA, STLG); // Call display function
sortByName(STN, STG, STT,STA, STLG); // Call sort students name function
displayData(STN, STG, STT,STA, STLG); // Call display function for the last time.
// close the files
name.close();
grade.close();
out.close();
system("pause");
return 0;
}
//========================Function to Read Data===================================
void readData(string stname[row], int stgrade[row][col])
{
name.open("Name.txt");
grade.open("Grade.txt");
int r, c;
for (r = 0; r < row; r++)
{
getline(name, stname[r]);
for (c = 0; c < col; c++)
{
grade >> stgrade[r][c];
}
}
}
//==================Function for Grade Total======================================
void stsum(int stgrade[row][col], int total[row])
{
int r, c;
for (r = 0; r < row; r++)
{
for (c = 0; c < col; c++)
total[r] = total[r] + stgrade [r][c];
}
}
//=========================Function for Average=================================
void staverage(int total[row], double average[row])
{
int r, c;
for (r=0;r<row;r++) {
for (c = 0; c < col; c++)
average[r] = static_cast<double>(total[r]/col);
}
}
//========================Function for Letter Grade==============================
void stlettergrade(double average[row], char ltrgrade[row])
{
int r;
for (r = 0; r < row; r++)
{
if (average[r] >= 90)
ltrgrade[r] = 'A';
else if (average[r] >= 80)
ltrgrade[r] = 'B';
else if (average[r] >= 70)
ltrgrade[r] = 'C';
else if (average[r] >= 60)
ltrgrade[r] = 'D';
else
ltrgrade[r] = 'F';
}
}
//=============================Function to Display Data=======================
void displayData(string stname[row], int stgrade[row][col], int total[row], double staverage [row], char ltrgrade[row])
{
out.open("Results.txt");
int r, c;
for (r = 0; r < row; r++)
{
out << stname[r] << setw(3);
for (c = 0; c < col; c++)
out << setw(5) << stgrade[r][c];
out << setw(5) << total[r]<< setw(5) << staverage[r]<< setw(5) << ltrgrade[r] << endl;
}
}
//=============================Function to Sort the Data By Letter Grade (i.e grade with A will occur first and grade with F last) =======================
void sortByLetterGrade(string stname[row], int stgrade[row][col], int total[row], double staverage[row], char ltrgrade[row])
{
int max;
// loop over the records
for(int i=0;i<row-1;i++)
{
max = i;
for(int j=i+1;j<row;j++)
{
// loop to get the ith student with highest A among the unsorted students
if(ltrgrade[j] < ltrgrade[max]) // since 'A' < 'B'
max = j;
}
// if ith student is not present in order, swap the values of student at index max with index i
if(max != i)
{
// swap the names
string tempStr = stname[i];
stname[i] = stname[max];
stname[max] = tempStr;
// swap the total
int tempInt = total[i];
total[i] = total[max];
total[max] = tempInt;
// swap the average
double tempDbl = staverage[i];
staverage[i] = staverage[max];
staverage[max] = tempDbl;
// swap the letter grade
char tempChr = ltrgrade[i];
ltrgrade[i] = ltrgrade[max];
ltrgrade[max] = tempChr;
// loop to swap the grades array contents
for(int c=0;c<col;c++)
{
tempInt = stgrade[i][c];
stgrade[i][c] = stgrade[max][c];
stgrade[max][c] = tempInt;
}
}
}
}
//=============================Function to Sort the Data By Name in ascending order=======================
void sortByName(string stname[row], int stgrade[row][col], int total[row], double staverage[row], char ltrgrade[row])
{
int min;
// loop over the records
for(int i=0;i<row-1;i++)
{
min = i;
// loop to get the ith student sorted by name
for(int j=i+1;j<row;j++)
{
if(stname[j] < stname[min])
min = j;
}
// if ith student is not present in order, then swap the ith student with min student
if(min != i)
{
// swap the names
string tempStr = stname[i];
stname[i] = stname[min];
stname[min] = tempStr;
// swap the total
int tempInt = total[i];
total[i] = total[min];
total[min] = tempInt;
// swap the average
double tempDbl = staverage[i];
staverage[i] = staverage[min];
staverage[min] = tempDbl;
// swap the letter grade
char tempChr = ltrgrade[i];
ltrgrade[i] = ltrgrade[min];
ltrgrade[min] = tempChr;
// swap the contents of grades arrray
for(int c=0;c<col;c++)
{
tempInt = stgrade[i][c];
stgrade[i][c] = stgrade[min][c];
stgrade[min][c] = tempInt;
}
}
}
}
//end of program
Please help!! I am supposed to write a program in C++ about student & grades. Needs...
I want to change this code and need help. I want the code to not use parallel arrays, but instead use one array of struct containing the data elements, String for first name, String for last name,Array of integers for five (5) test scores, Character for grade. If you have any idea help would be great. #include #include #include #include using namespace std; const int NUMBER_OF_ROWS = 10; //number of students const int NUMBER_OF_COLUMNS = 5; //number of scores void...
Hello I am having trouble with a connectFour java program. this issue is in my findLocalWinner method, it declares a winner for horizontal wins, but not for vertical. if anyone can see what im doing wrong. public class ConnectFour { /** Number of columns on the board. */ public static final int COLUMNS = 7; /** Number of rows on the board. */ public static final int ROWS = 6; /** Character for computer player's pieces */ public static final...
Can somebody help me with this coding the program allow 2 players play tic Tac Toe. however, mine does not take a turn. after player 1 input the tow and column the program eliminated. I want this program run until find a winner. also can somebody add function 1 player vs computer mode as well? Thanks! >>>>>>>>>>>>>Main program >>>>>>>>>>>>>>>>>>>>>>> #include "myheader.h" int main() { const int NUM_ROWS = 3; const int NUM_COLS = 3; // Variables bool again; bool won;...
Program is in C++, program is called airplane reservation. It is suppose to display a screen of seating chart in the format 1 A B C D E F through 10. I had a hard time giving the seats a letter value. It displays a correct screen but when I reserve a new seat the string seats[][] doesn't update to having a X for that seat. Also there is a file for the struct called systemUser.txt it has 4 users...
Hello, I am working on a project for my C++ class, I have the vast majority of the code figured out but am running into a few issues. Mainly updating each * to an X. The problem is as follows:(Airplane Seating Assignment) Write a program that can be used to assign seats for a commercial airplane. The airplane has 13 rows, with six seats in each row. Rows 1 and 2 are first class, rows 3 through 7 are business...
Hello, I am trying to write this program and have received a "Segmentation Fault" error but cannot seem to figure out where. I haven't been able to find it and have been looking for quite a while. The goal is to basically create a version of Conway's Game of Life. I am able to generate a table if the input values for rows and columns are equal, but if they are not I receive a segmentation fault and cannot continue...
Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...
I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I just have to explain a lot so you understand how the program should work. In C programming, write a simple program to take a text file as input and encrypt/decrypt it by reading the text bit by bit, and swap the bits if it is specified by the first line of the text file to do so (will explain below, and please let me...
For the following task, I have written code in C and need help in determining the cause(s) of a segmentation fault which occurs when run. **It prints the message on line 47 "printf("Reading the input file and writing data to output file simultaneously..."); then results in a segmentation fault (core dumped) I am using mobaXterm v11.0 (GNU nano 2.0.9) CSV (comma-separated values) is a popular file format to store tabular kind of data. Each record is in a separate line...
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...