Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Having issue with this code running properly. Program compiles but is unable to find file. Code thus far (comments are required): // Meredith Petersen //

Having issue with this code running properly. Program compiles but is unable to find file. Code thus far (comments are required):

// Meredith Petersen // Programming Assignment 1 // CSC 210 - Spring 2020 // January 20, 2020 // This program will read vet customer and service data and calculate the total bill.

//Create .h file with function abstraction and 2 structures #include #include #include #include using namespace std;

//Customer detail structure struct Customer { stringpetName; stringpetType; doubletotalBill; intnumberOfServices; intdescriptionService[5]; };

//Service detail structure struct Service{ intproductNumber; double price; string description; };

//Function prototypes intreadServices(Service services[], string filename); intreadCustomers(Customer customer[], string filename); voidcalculate(struct Service*, int, struct Customer*, int); void display(struct Customer*, int);

// Implementation class

// Function reads service file data and store corresponding values

intreadServices(Service services[], string filename) { //File object set ifstream in1(filename); //Line count intserviceCnt = 0; //File open error check if (!in1) { cout << "file not found!!!" << endl; exit(0); } //Read and store data and increment count while (!in1.eof()) { in1 >> services[serviceCnt].productNumber >> services[serviceCnt].price >> services[serviceCnt].description; serviceCnt++; } //Close file in1.close(); //Return count returnserviceCnt; } //Function to read customer details from file. //Store each customer details incustomer struct array. //Keep track of the count of customers and return value

intreadCustomers(Customer customers[], string filename) { //File path set ifstream in2(filename); //Variable to keep customer count intcustomerCnt = 0; //File open error check if (!in2) { cout << "file not found!!!" << endl; exit(0); } //Read until end of file while (!in2.eof()) { //Set service count=0 customers[customerCnt].numberOfServices = 0; //Read pet name and type from file and store in2 >> customers[customerCnt].petName >> customers[customerCnt].petType; int val; in2 >> val; //Read services until -1 and store while (val != -1) { customers[customerCnt].descriptionService[customers[customerCnt].numberOfServices++] = val; in2 >> val; } customerCnt++; } //close file in2.close(); //Return count of customers returncustomerCnt; } //Function loop through service and customers array //Error services store in error file //Otherwise add into bill //Calculate total bill of each customer

voidcalculate(struct Service* services, intserviceCnt, struct Customer* customers, intcustomerCnt) { ofstream out("error.txt"); //Loop through customers for (inti = 0; i < customerCnt; i++) { customers[i].totalBill = 0; //Loop through each customer services for (int j = 0; j < customers[i].numberOfServices; j++) { bool found = false; //Loop through services for (int k = 0; k < serviceCnt; k++) { //Match and add into bill if (services[k].productNumber == customers[i].descriptionService[j]) { found = true; customers[i].totalBill += services[k].price; } } //Otherwise write error in error file if (!found) { out << "Service number " << customers[i].descriptionService[j] << " of pet "<< customers[i].petName<<" not found!!!" << endl; } } } //close error file out.close(); } //Display each customer details void display(struct Customer* customers, intcustomerCnt) { for (inti = 0; i < customerCnt; i++) { cout <

//Main program //Declare struct arrays //Get 2 input files //Call appropriate functions

int main() { //Create struct arrays Customer customers[30]; Service services[50]; string filename; //Prompt for service details file name cout << "Enter service file name: "; cin >> filename; //Read file data and return count intserviceCnt=readServices(services, filename); //Prompt for customer details file name cout << "Enter customer file name: "; cin >> filename; //Read file and return count intcustomerCnt = readCustomers(customers, filename); //Call function to calculate each customer bill calculate(services, serviceCnt, customers, customerCnt); //Display total bill details display(customers, customerCnt); return 0; }

Program requirements:

customers.txt reads:

Spot Feline 1 2 -1

Iorek Canine 1 4 8 -1

Milo Feline 1 13 -1

Felix Canine 1 7 3 -1

Shadow Canine 1 10 -1

Cosmo Feline 1 11 -1

Bruce Canine 1 12 -1

Jackson Feline 1 9 -1

services.txt reads:

1. 25.00 Exam

2. 50.00 Antibiotic

3. 60.00 Previcox

4. 10.00 Ear-Care

5. 15.00 Vaccinnation-Rabies

6. 100.00 Spay/Neuter

7. 500.00 Knee-Surgery

8. 25.00 Nail-Trim

9. 40.00 Feline-Leukemia-Vaccine

10. 55.00 Canine-5-in-1-Vaccine

11. 55.00 Feline-3-in-1-Vaccine

Program Requirement descriptions (code must include descriptive comments):

Read vet customer and service data and compute total bill. Use arrays of structures to hold data to process.

  1. You are to read a data file (provided) containing customer data for veterinary services provided and calculate the total bill.

The customer file consists of several rows of data that contain:

Pet name (single word for simplicity), Pet Type (species), any number of services, -1 indicating end of the record

The service number is a number representing a provided service. This will correspond to a number in the services file, however, there may be errors in the customers file, i.e., a service number may not exist in the services file.

For example:

Fluffy Feline 1 3 5 -1

Iorek Canine 2 3 5 -1

  1. Create a structure to contain the information for a customer:

Pet Name

Pet Type

Total Bill

Number of Services

Description of Services (a maximum array size of 5)

Declare the structure in a header file.

  1. You are also to read a data file (provided) containing service information, which consists of a service number, a price and a description.

For example:

1 15.95 Exam

2 12.22 Antibiotics

Service 1 has a price of 15.95 and a description of Exam, service 2 has a price of 12.22 and a description of Antibiotics

  1. Create a structure to contain the information for the products:

Product Number

Price

Description

Declare the structure in the header file

  1. Declare the structures for the customer and service data in the header file. Declare an array variable for each of the customer and service structures LOCALLY in main. Declare an array size for the customer data as 30; for the service data as 50.

  1. Read and store the service data into the service structure array. Read until end of file. Use a counter to count and track how many rows read. Pass the counter into any processing functions that loop through structure array (do not use a global variable).

  1. Read and store the customer data into the customer structure array. Read until end of file. Use a counter to count and track how many rows read. Pass the counter into any processing functions that loop through the structure array (do not use a global variable).

  1. Calculate the total bill for each customer while reading the data and then store in the structure. You ARE NOT to store the product/number sold pairs in the customer array for each customer, you are to store the service descriptions in the services array inside the structure. The total bill calculation will involve reading the service data into the service array structure first and looking up the price based on the service number while reading the customer data.

  1. Also, tally the number of services and store in the customer structure to indicate how many services were provided to the customer for the output function.
  1. Read and store the service data into the structure array using a function.
  1. Read and store the customer data in into the structure array using a function.

  1. You may read the service and customer data in the same function.

  1. Process the all customer data using a function. This may be included in the read function. Checking for valid service numbers. If an invalid service number is encountered in the customer data, write the invalid service number to an error file with an appropriate message of your choice. DO NOT include the service in the total bill calculation.

  1. Using a function, output the computed bill data to the console (cout) and to an output data file including the following information. This must be a function called from main:

Pet Name Pet Type Total Bill Services (list all services)

Include dollar signs before money values and ensure each line of data is neat and readable. All monetary values must have two decimal places.

  1. Use a function to open all input and output files. Request all file names from the user EXCEPT the error file, which you may choose and hard code in the program.
  1. Main should contain function calls only; no data or output processing.

  1. All functions should be in a separate code file (*.cpp). The assignment will involve 2 cpp files and 1 header file.

  1. Close all files prior to program end. Close the files using a function.
  1. All structure DECLARATIONS, global constants and function prototypes MUST be in a header file. Include the header file in the program. DO NOT CODE THE FUNCTIONS IN THE HEADER FILE. Functions MUST be coded in the .cpp file AFTER main.
  1. Each function must have required documentation (pre and post conditions).

(There is also a readme file required, here is an example for a different program, I am struggling with making a summary for this one)

Program: ProgramExample.cpp

Author: Pam Smith

Input File: myFile.txt

Execute in Dev-C++: Open ProgramExample.cpp

Select Compile and Run

When program asks for file name, enter: myFile.txt

Execute stand alone: ProgramExample 1997 // This is not REQUIRED

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

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions