Write a C++ program called studentScholarship with a main function. The studentS
ID: 3627993 • Letter: W
Question
Write a C++ program called studentScholarship with a main function.The studentScholarship C++ program will have two two-dimensional and one one-dimensional parallel arrays. The first array is for a student’s first name. The second array is for a student’s last name. And the third array is for a student’s scholarship amount. This program also will have a one-dimensional array for a file name called “scholarshiplist.txt”.
The main function will enable the user to enter at least 9 different first names, last names, and scholarship amounts. It will store these values in the arrays.
Input Validation: The user must enter positive scholarship amounts. If the user enters 0.00 or negative scholarship amounts, validate the amounts with a loop.
Write three function prototypes and three functions in addition to the main function.
One function (in addition to main), the display function, will be called in main and the function call will pass the three arrays by argument to a function with the arrays as parameters. This function will use a loop to display at least 9 different first names, last names, and scholarship amounts that are values in the arrays. The display will have a heading like this:
Last Name, First Name Scholarship Amount
For each entry in the arrays, the display will look like the following:
last name, first name scholarship amount
A second function (in addition to main), the write function, also will be called in main and the function call will pass the arrays, include the file array, by argument to a function with the arrays as parameters. This function will open a file, write the student scholarship list – including the last name, the first name, and the scholarship amount – to the file using a loop, and then close the file.
A third function (in addition to main), the read function, also will be called in main and the function call will pass the arrays, including the file array, by argument to a function with the arrays as parameters. This function will open a file, read the student scholarship list from the file – including the last name, the first name, and the scholarship amount – using a loop, and then close the file. This third function will then call the display function created above and pass the three arrays by argument to the display function with the arrays as parameters.
Explanation / Answer
please rate - thanks
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void display(char[][10],char[][15],double[],int);
void write(char[][10],char[][15],double[],char[],int);
void read(char[][10],char[][15],double[],char[]);
int main()
{char last[20][15],first[20][10],filename[]={"scholarshiplist.txt"};
double amount[20];
int i, count;
cout<<"How many students are there? ";
cin>>count;
while(count<9||count>20)
{cout<<"must be between 9 and 20 ";
cout<<"How many students are there? ";
cin>>count;
}
for(i=0;i<count;i++)
{cout<<"Enter first name for student "<<i+1<<": ";
cin>>first[i];
cout<<"Enter "<<first[i]<<"s last name: ";
cin>>last[i];
cout<<"Enter "<<first[i]<<"s scholarship amount: ";
cin>>amount[i];
while(amount[i]<=0)
{cout<<"must be >0 ";
cout<<"Enter "<<first[i]<<"s scholarship amount: ";
cin>>amount[i];
}
}
display(first, last,amount,count);
write(first,last,amount,filename,count);
read(first,last,amount,filename);
system("pause");
return 0;
}
void display(char f[][10],char l[][15],double a[],int count)
{int i;
cout<<"Last Name, First Name Scholarship Amount ";
for(i=0;i<count;i++)
cout<<left<<l[i]<<", "<<f[i]<<setprecision(2)<<fixed<<setw(5)<<
" "<<right<<"$"<<a[i]<<endl;
}
void write(char f[][10],char l[][15],double a[],char file[],int count)
{ofstream out;
int i;
out.open(file);
for(i=0;i<count;i++)
out<<l[i]<<" "<<f[i]<<" "<<a[i]<<endl;
out.close();
out.clear();
}
void read(char f[][10],char l[][15],double a[],char file[])
{ifstream in;
int i=0;
in.open(file);
in>>l[i];
while(in)
{in>>f[i]>>a[i];
i++;
in>>l[i];
}
display(f, l,a,i);
in.close();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.