1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
likoan [24]
3 years ago
14

Create a function named PrintStudents, which takes a string input filename and an integer minimum score value and a string outpu

t file name as a parameters. The function will read the student scores and names from the file and output the names of the students with scores greater than or equal to the value given. This function returns the integer number of entries read from the file. If the input file cannot be opened, return -1 and do not print anything to the file.Read each line from the given filename, parse the data, process the data, and write the required information to the file.Each line of the file contains , , . Read and parse the data, then write to the output file the names and classes for scores matching the criteria.Example: With the following data and value of 80:Constance Shelton, 67, APPM 2002Charlotte Edwards, 85, CSCI 1300Alyssa Hill, 78, MATH 1000Pat Owens, 75, HUMN 1342Shannon Jimenez, 96, LING 2000Kristen Swanson, 80, PSYC 1001Jim Schwartz, 60, CVEN 3241Your function should return 7 and output to the file should contain:Charlotte Edwards, CSCI 1300Shannon Jimenez, LING 200Kristen Swanson, PSYC 1001You only need to write the function code. Our code will create and test your class.HINT: We have provided a function that may make the parsing easier:int split(string s, char sep, string words[], int max_words);
Computers and Technology
1 answer:
givi [52]3 years ago
4 0

Answer:

The code is implemented below on C++

Explanation:

#include <iostream>

#include <fstream>

#include <string>

using namespace std;

// function declaration

int PrintStudents(string inputFile, int min_score,string outputFile);

int split(string s,char sep, string words[], int max_words );

int main() {

// test the function

              int n = PrintStudents("students.txt",80,"outStudents.txt");

              if(n != -1)

                             cout<<"\n No. of students : "<<n<<endl;

              else

                             cout<<"\n No such file exists";

              return 0;

}

// function to write the details of the students whose score >= min_score

// inputs : input file, minimum score and output file

// output : number of records read, -1 if error

int PrintStudents(string inputFile, int min_score,string outputFile)

{              // open the input file

              ifstream fin(inputFile.c_str());

              // if input file can be opened

              if(fin.is_open())

              {              // open the output file for writing

                             ofstream fout(outputFile.c_str());

                             int n=0,score;

                             string line;

                             string words[3];

                             // read till the end of file

                             while(!fin.eof())

                             {

                                            getline(fin,line);

                                            n++;

                                            // get the score from the record read

                                            score = split(line,',',words,3);

                                            // check if score>=min_score, then write to output file

                                            if(score >= min_score)

                                                           fout<<words[0]<<", "<<words[2]<<"\n";

                                            if(fin.eof())

                                                           break;

                             }

                             // close the files

                             fin.close();

                             fout.close();

                             return n; // return the number of records read

              }else

              {

                             fin.close();

                             return -1; // file not found

              }

}

// function to split a string on a given separator and return the score

// inputs : string , word separator, array of words and max_words

// output is the score

int split(string s,char sep, string words[], int max_words )

{

              int index=0,i=0 ;

              //loop to extract the words from the line

              while(s.find(sep,index+1)!= -1){

                             words[i] = s.substr(index,s.find(sep,index+1)-index);

                             i++;

                             index = s.find(sep,index+1)+2;

              }

              words[i] = s.substr(index); // extract the last word

              // convert to integer and return the score

              return(stoi(words[1]));

}

You might be interested in
What did you predict will happen? Check all that apply. The lioness will attack Thisbe. Thisbe will stay hidden in the cave to a
sesenic [268]

Hi,


Everything applies. It is impossible to predict based on the current data. All scenarios are possible with equal possibility.


Hope this helps.

r3t40

5 0
4 years ago
Read 2 more answers
Consider the following Ordinary Differential Equation:ODE : d 2y dx2 + 5 dy dx + 4y = 1 x ∈ [0; 1] BC : y(0) = 1; y 00(1) = 0 Us
tatuchka [14]

Answer:

have to go back and get a job that I don't need anymore help with that I can get a good feel about what you want me 50,000 to be able and how you feel when I get back into town for the weekend so we will have a lot to catch on the weekend and I will be sure that I will follow up on

3 0
3 years ago
What is the definition of assiduous?
LuckyWell [14K]

Answer:

showing great care and perseverance.

6 0
3 years ago
Read 2 more answers
if your audience seems confused about a previous slide, in presenter view, whats the best way to jump back to a previous point i
SOVA2 [1]

Answer:

You can go back to that point towards the end of the presentation  or find where it would link later on in the presentation. Then you can ask if there are any questions and if the audience are willing to ask them you can go ahead and explain it.

Explanation:

8 0
3 years ago
Which access method would be most appropriate if your manager gave you a special cable and told you to use it to configure the s
GrogVix [38]
Console Port Method

Connecting a computer to a Cisco device through the console port requires a special console cable.
8 0
3 years ago
Other questions:
  • Cartoon Disney question: Snow White asks the dwarfs a question. 2 of them are lying and 3 can only say the truth. The continuati
    10·1 answer
  • Which process alters readable data into unreadable form to prevent unauthorized access known as?
    8·1 answer
  • The design of computers, devices, and media in a network is categorized as either client/server or peer-to-peer. what is the ter
    8·1 answer
  • Design state machines to control the minutes and hours of a standard 24 hour clock. Your clock should include an AM/PM indicator
    11·1 answer
  • Which are examples of ribbon customizations?
    11·1 answer
  • Read the following code:
    6·1 answer
  • Heyyyyyy<br> byeeeeeeeeeeeeeeeeeeeeeee
    15·2 answers
  • How to recover deleted photos after deleting from recently deleted
    13·2 answers
  • 236. A system such as a printer, smart TV, or HVAC controller, typically uses an operating system on what is called a:
    13·2 answers
  • How to get flash to work on chrome?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!