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

New to C programming and I am stuck. The program will print "no input" if no...
New to C programming and I am stuck. The program will print "no input" if no input is given. If a command line argument is given the program will print "input:" followed by the user input. Below is the code I put together to do as desired but I get errors. What do I need to fix to get my code to compile correctly? #include <stdio.h> #include <stdlib.h> int main () { char input; scanf("%c", &input); if (input == NULL)...
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...
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...
Hello, I very stuck on this c++ blackjack project and was wondering if anyone can offer...
Hello, I very stuck on this c++ blackjack project and was wondering if anyone can offer help and guidance on this subject can someone help he with part 4 i have no idea how to approach the problem and how to do it I have compeleted a few parts to this project they are listed below Part 1 – Displaying Cards Write a function to display (print) a card. sample program output void displayCard(int card) Prints the name of the...
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...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Important! Consider which control structures will work best for which aspect of the assignment. For example, which would be the best to use for a menu?...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Your code must contain at least one of all of the following control types: nested for() loops a while() or a do-while() loop a switch() statement...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT