Question

In: Computer Science

Hello, I stuck doing c++ program The program will be recieved from the user as input...

Hello, I stuck doing c++ program

The program will be recieved from the user as input name of an input file and and output.file.

then read in a list of name, id# and score from input file (inputFile.txt)

and initilized the array of struct.

find the student with the higher score and output the students info in the output file
obtain the sum of all score and output the resurl in output file.
prompt the user for a name to search for, when it find the, will output to a file(output)
prompt for another name until the word done is typed.
calclate and output the sum of all scores for the found name
header file.   
*dont make array size a global concstan. it must pass it as a parameter as necessary
function for

input function ( propagate the array of structs to real in all the data) “one array of a struct “, must declare a struct with three members(names, ids, scores). read all the data frim infile.txt
search function score
sum function
search fuction name (search for a name and return the proper index
console input / output

type input file name : inputFile.txt

type output file name : outputFile.txt

type student’s name you are searching for (type done to exit) : Emma

type student’s name you are searching for (type done to exit): Jason

type student’s name you are searching for (type done to exit): done

Thank you!

outputFile.txt

high score

ID # NAME SCORE

—— —————- ————

9987 Emma. 82.96

total score for all students:

280.78

Search Names:

ID # NAME SCORE

—— —————- ————

9987 EMMA 82.96

1923 JEFF 80.93

9486 JAMES 39.92

TOTAL SCORE: 203.81

inputFile.txt

EMMA KIM
9987 82.96

JEFF PETTERSON
1923 80.93

JAMES MORGAN

9486 39.92

CLARK HOFFMAN
3745 76.97

Solutions

Expert Solution

Code:

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

using namespace std;


struct Student
{
   int id;
   string name;
   float score;
};

void readData(Student students[10],int& size,string fileName)
{
   ifstream fin;

   fin.open(fileName);

   if (!fin.is_open())
       return;

   int si = 0;

   while (!fin.eof())
   {
       string name;
       getline(fin, name);
       string line;
       getline(fin, line);
       stringstream ss(line);

       int id;
       float score;
       ss >> id;
       ss >> score;

       Student s;
       s.name = name;
       s.id = id;
       s.score = score;
       students[si++] = s;
   }

   size = si;
}

float calculateTotalScore(Student stu[],int& size)
{
   float sum = 0.0;
   for (int i= 0;i<size;i++)
   {
       sum += stu[i].score;
   }

   return sum;
}

Student searchStudent(Student stu[],int size,string name,float& totalScore)
{
   Student s;
   for (int i = 0;i < size;i++)
   {
       if(stu[i].name.find(name) != string::npos)
       {
           totalScore += stu[i].score;
           s = stu[i];
           break;
       }
   }
   return s;
}

void printtoFile(ofstream& fout,Student s)
{
   fout << s.id << " " << s.name << " " << s.score<<"\n";
}

int main()
{
   Student s[10];
   int size;
   string inFile, outFile;

   cout<<"\ntype input file name : ";
   cin >> inFile;

   cout << "\ntype output file name : ";
   cin >> outFile;

   cout << "\n";

   readData(s, size,inFile);

   calculateTotalScore(s, size);

   ofstream fout(outFile);

   fout << "ID Name Score\n";
   fout << "------------------------------\n";
   for (int i = 0;i < size;i++)
   {
       printtoFile(fout, s[i]);
   }


   string str;
   float totalScore = 0.0;
   do
   {

       cout << "\n\ntype student’s name you are searching for (type done to exit) :";
       cin >> str;
       printtoFile(fout,searchStudent(s, size, str, totalScore));

   } while (str != "done");

   fout << "\nTotal Score : " << totalScore;

   return 0;

}


Related Solutions

Hello! I am doing an advertisment campaign, I recieved the most vague instructions ever, can anyone...
Hello! I am doing an advertisment campaign, I recieved the most vague instructions ever, can anyone clarify if you have any idea? Step 1: SWOT Analysis for the Advertising Client (20%)  Key communications goals should emerge from this analysis Step 2: Target Market Assignment (20%)  Who, what need, where, when, why client solution and how (solution) Step 3: Brand Identity Assignment (20%)  Key image, message, positioning and rationale supported by Steps 1 &2 Step 4: Promotional Strategy...
2) Write a C++ program that accepts a sentence as an input from the user. Do...
2) Write a C++ program that accepts a sentence as an input from the user. Do the following with the sentence. Please use C++ style string for this question. 1) Count the number of letters in the input 2) Change all lower case letters of the sentence to the corresponding upper case
Write a C++ or Java program that reads an input graph data from a user. Then,...
Write a C++ or Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number ofvertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2...
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
Hello this is for C++ language. I am currently stuck on creating my api for Day...
Hello this is for C++ language. I am currently stuck on creating my api for Day Trading Stocks. as follows I need an api for *//Function Signature * * parameter: * * Return Value: ** *// Write the following function taking in an integer vector (vector &prices) consisting of all prices, in chronological order, for an hypothetical instrument. Your function recommends the maximum profit an investor can make by placing AT MOST one buy and one sell order in the...
Hi i need a c++ program that can convert charactor into numbers pseodocode user input their...
Hi i need a c++ program that can convert charactor into numbers pseodocode user input their name for example john every single charactor should have a value so it return correct result eg: j=2, o=1, h=7,n=2 and display these numbers if you may need any question to ask me, i will be very happy to answer them. Thanks! example project close but not accurate #include #include #include #include #include #include #include #include #define INPUT_SIZE 8 using namespace std; // Function...
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
Write a program in c++ that prompts the user to input a coin collection of number...
Write a program in c++ that prompts the user to input a coin collection of number of quarters, dimes, nickels and pennies. The program should then convert the coin collection into currency value as dollars. The coin values should all be whole numbers and the resulting currency value should be displayed with two decimals. An example of user interaction is as follows: Coin Convertor Enter number of quarters: 3 Enter number of dimes: 1 Enter number of nickels: 4 Enter...
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
Using C++ Create a program that asks the user to input a string value and then...
Using C++ Create a program that asks the user to input a string value and then outputs the string in the Pig Latin form. - If the string begins with a vowel, add the string "-way" at the end of the string. For “eye”, it will be “eye-way”. - If the string does not begin with a vowel, first add "-" at the end of the string. Then rotate the string one character at a time; that is, move the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT