Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the babynames.cpp program so the most common names given to 10 percent of the population are saved to a file output.txt. #include #include #include

Modify the babynames.cpp program so the most common names given to 10 percent of the population are saved to a file output.txt.

#include #include #include

using namespace std; /** Reads name information, prints the name if total >= 0, and adjusts the total. @param in_file the input stream @param total the total percentage that should still be processed */

void process_name(ifstream &in_file, ofstream &out_file, double &total) { string name; int count; double percent; in_file >> name >> count >> percent; if (in_file.fail()) { return; } if (total > 0) {

//write out_file

int main() {

ifstream in_file;

ofstream out_file;

in_file.open("babynames.txt");

out_file.open("output.txt");

if (in_file.fail()) { return 0; }

double boy_total = 10; double girl_total = 10;

while (boy_total > 0 || girl_total > 0) { int rank; in_file >> rank;

if (in_file.fail()) { break; } out_file

process_name(in_file, out_file, boy_total); process_name(in_file, out_file, girl_total);

out_file

in_file.close(); out_file.close();

string line; in_file.open("output.txt");

if (in_file.fail()) { return 0; }

while (getline(in_file, line)) { cout

this is what i have so far and this is the outcome but how do I get the test to not produce outcome and only file content?

image text in transcribed

Expected output This test case should produce no output

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

6.5. Prove the properties of the radar ambiguity function.

Answered: 1 week ago

Question

How is the NDAA used to shape defense policies indirectly?

Answered: 1 week ago

Question

demonstrate the importance of induction training.

Answered: 1 week ago