Question
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 //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.
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
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.
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
Product Number Price Description Declare the structure in the header file
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.
|
(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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started