Question

Stuck on this computer science assignment

Write a program that demonstrates binary searching through an array of strings and finding specific values in an corresponding parallel double array.  In all cases your output should exactly match the provided solution.o.
Provided files:

Assignment.cpp  - starter assignment with function prototypes
companies.txt   - file for program to read. 
earnings.txt    - file for program to read. 
Input1.txt     
Input2.txt      - Test these inputs out manually, or use stream redirection
Input3.txt      - These inputs are based on the provided companies.txt and earnings.txt, 


Because you will not be doing file output in this assignment, only input, both your solution and the provided one should work from the companies.txt and earnings.txt files.

This program will read from two different files, companies.txt which will have pre-sorted company names with no spaces separated by newlines, and earnings.txt which will have double values corresponding to each company, also separated by newlines.  There will be the same number of entries in each file, at max ten.

The program should read each file.  Then in a loop print out a menu displaying first a single newline, then company names and corresponding earnings, followed by a prompt.  Note that the print of the menu requires a precise number of space characters (not tabs) to be entered between the name of the company and the earnings.  This space string will vary based on the size of the corresponding company name.

At the prompt the user will enter a company name.  You will binary search the array of companies to find the index of that name, if it is present.  Because the input file will be provided in alphabetical order, provided you read it in the same order it is written you should be able to search the array without modifying it.  If the entered company name is not present you will notify the user and prompt to enter another name.  Every binary search should print out the pivots it finds while searching, prepended with a tab character, as the solution.o does.

When you successfully find a user entered name, you should store its corresponding earnings, and prompt the user to enter another name.  Once the user has entered three company names successfully, you should display the average of three found earnings.  At this point, after displaying the average, you should prompt the user whether they want to enter another three names or quit by entering lowercase or capital q.

You should setprecision to 15 in cout for this assignment.

You do not have to handle:
Missing input file
Malformed file (you will always have the same number of names and earnings.  Company names and earnings will never contain a space)
Malformed user input, except missing company name, that does have to be handled.
Out of order company file.  The company names will be in alphabetical order, you do not have to sort them.
At the end enter q to quit prompt, you can assume the user will enter a single character of input.

________________________________

We must use this template:

#include <iostream>
#include <fstream>

using namespace std;

bool DEBUG = false;
int SIZE = 10;
int CHOICESIZE = 3;
int MAX_COMPANY_NAME_LENGTH = 20;

//the integer value returned will be the index of value_to_find in array_to_search or -1 if it is not present
int binarySearch(const string* array_to_search, string value_to_find, int array_length);

//reads from earnings.txt double values into the array argument.
void readValues(double* array_to_store_in, int array_length);

//reads from companies.txt string values into the array_to_store_in argument.
//the integer value returned will be the number of companies read from the file.
//It will be between 3 and 10 depending on the input file
//the array_to_store_spaces will be filled with " " space characters so that each member of the array corresponds with a company name to have a total length of MAX_COMPANY_NAME.
//Therefore if a company name at index 3 was "General_Motors" the value in the spaces array at index 3 would be " " or six spaces.
int readCompanies(string* array_to_store_in, string* array_to_store_spaces, int array_length);

//prints out the menu of company names and earnings.
void printMenu(const string* array_companynames, const string* array_spaces, const double* array_earnings, int array_length);


int main(){
}

____________________

Here's what's inside the .txt files

Input1.txt

Aperture_Science
Malo_Mart
Silph_Co
n
MTT_Resort
Malo_Mart
Shinra_Inc
q

_______________________

Input2.txt

aaa
Cannon_Travel
_Science_Inc
Gadd_Science_Inc
zzz
Recettear
Q

______________

Input3.txt

Not_A_Company
MTT_Resort
Shinra_Inc
Silph_Co
n
broken_name
Recettear
bad_name
Malo_Mart
another_bad
Silph_Co
Q

______________

earnings.txt

0.52
9643.21
20.45
235434.2
1753544.3
820000
232.12
25768.45

______________

companies.txt

Aperture_Science
Cannon_Travel
Gadd_Science_Inc
MTT_Resort
Malo_Mart
Recettear
Shinra_Inc
Silph_Co

__________________

Here's an example of a run of the solution:

Aperture Science Cannon Travel Gadd Science Inc MI


______________________

Thanks guys!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <fstream>

using namespace std;

bool DEBUG = false;
int SIZE = 10;
int CHOICESIZE = 3;
int MAX_COMPANY_NAME_LENGTH = 20;

//the integer value returned will be the index of value_to_find in array_to_search or -1 if it is not present
int binarySearch(const string* array_to_search, string value_to_find, int array_length);

//reads from earnings.txt double values into the array argument.
void readValues(double* array_to_store_in, int array_length);

//reads from companies.txt string values into the array_to_store_in argument.
//the integer value returned will be the number of companies read from the file.
//It will be between 3 and 10 depending on the input file
//the array_to_store_spaces will be filled with " " space characters so that each member of the array corresponds with a company name to have a total length of MAX_COMPANY_NAME.
//Therefore if a company name at index 3 was "General_Motors" the value in the spaces array at index 3 would be " " or six spaces.
int readCompanies(string* array_to_store_in, string* array_to_store_spaces, int array_length);

//prints out the menu of company names and earnings.
void printMenu(const string* array_companynames, const string* array_spaces, const double* array_earnings, int array_length);


int main(){
}

____________________

Here's what's inside the .txt files

Input1.txt

Aperture_Science
Malo_Mart
Silph_Co
n
MTT_Resort
Malo_Mart
Shinra_Inc
q

Add a comment
Know the answer?
Add Answer to:
Stuck on this computer science assignment Write a program that demonstrates binary searching through an array...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. You should also have a parallel array to store the names of the 12 months. The program should read the Month's names, and the temperatures from a given input file called temperature.txt. The program should output the highest and lowest temperatures for the year, and the months that correspond to those temperatures. The program must use the following functions:...

  • Write a program that has an array of at most 50 strings that hold people’s names...

    Write a program that has an array of at most 50 strings that hold people’s names and phone numbers. You can assume each string’s length is no more than 40. You may make up your own strings, or use the following: "Becky Warren, 555-1223" "Joe Looney, 555-0097" "Geri Palmer, 555-8787" "Lynn Presnell, 555-1212" "Holly Gaddis, 555-8878" "Sam Wiggins, 555-0998" "Bob Kain, 555-8712" "Tim Haynes, 555-7676" "Warren Gaddis, 555-9037" "Jean James, 555-4939" "Ron Palmer, 555-2783" The program should ask the user...

  • Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( );...

    Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( ); // constructor ~Salesperson( ); // destructor Salesperson(double q1, double q2, double q3, double q4); // constructor void getsales( ); // Function to get 4 sales figures from user void setsales( int quarter, double sales); // Function to set 1 of 4 quarterly sales // figure. This function will be called // from function getsales ( ) every time a // user enters a sales...

  • Star Database Program. This is a more sophisticated assignment, it will take longer to do. Write...

    Star Database Program. This is a more sophisticated assignment, it will take longer to do. Write a program which uses file IO, loops, and function calls. The following files are provided in pub: Assignment.cpp stars.dat solution_stars.dat solution.o when you log in the first time, make a directory for this project mkdir prog3 then copy down the files. (WARNING! This will overwrite any file in the directory named Assignment.cpp, so don't copy down Assignment.cpp if you have already done work): cp...

  • Write a program that will take input from a file of numbers of type double and...

    Write a program that will take input from a file of numbers of type double and output the average of the numbers in the file to the screen. Output the file name and average. Allow the user to process multiple files in one run. Part A use an array to hold the values read from the file modify your average function so that it receives an array as input parameter, averages values in an array and returns the average Part...

  • COSC 1437 C++2 Project Assignment 3 Description: Computer Science Department is evaluating its professors to see...

    COSC 1437 C++2 Project Assignment 3 Description: Computer Science Department is evaluating its professors to see which professor has the highest rating according to student input. You will create a ProfessorRating class consisting of professor Name and three ratings. The three ratings are used to evaluate easiness, helpfulness, and clarity. The value for each rating is in the range of 1 to 5, with 1 being the lowest and 5 being the highest. Your program should contain the following functionalities:...

  • This lab is to give you more experience with C++ Searching and Sorting Arrays Given a...

    This lab is to give you more experience with C++ Searching and Sorting Arrays Given a file with data for names and marks you will read them into two arrays You will then display the data, do a linear search and report if found, sort the data, do a binary search. Be sure to test for found and not found in your main program. Read Data Write a function that reads in data from a file using the prototype below....

  • MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random...

    MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random words from a training set as explained in the lectures on graphs. Do not hard-code the training set! Read it from a file. A suggested format for the input file: 6 a e m r s t 10 ate eat mate meet rate seat stream tame team tear Here are some suggestions for constants, array declarations, and helper functions #include <iostream> #include <fstream> #include...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT