Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use C++: Download Lab09.cpp (the given code) and the two input files music.txt and writer.txt. Read the given code. There is a base class called

Use C++:

Download Lab09.cpp (the given code) and the two input files music.txt and writer.txt. Read the given code. There is a base class called Person which stores a person's firstName and lastName. There is a Musician derived class and a Writer derived class (both derived from Person). A musician "is a" person. A writer "is a" person. The Musician derived class holds an additional member variable for the musician's instrument. The writer derived class holds an additional member variable for the writer's genre. These classes are implemented for you.

1) Please implement the Musician derived class and a Writer derived class.

2) Please implement the main() function to accomplish the following tasks:

- Scan the data from the input file and load that data in an array of Musician objects and an array of Writer objects.

- The two arrays should be allocated dynamically, so they are the exact length that is required according to their respective input file.

- Point the content of each array before releasing the memory and exiting the program.

- The variables numerOfMusicians and numberOfWriters (shown below) are intended to store the length of corresponding arrays. The string variables str1, str2, and str3 are intended to temporarily hold firstName, lastName, and third variable (instrument or genre) as each line is read from its input file and then set into its object.

int main() {

int numberOfMusicians = 0; int numberOfWriters = 0; string str1, str2, str3; ifstream fin;

// TODO: Open the file music.txt. Print an error message and exit // the program if the file cannot be opened. 5 pts.

// TODO: Read the number at the beginning of the text file. That number // indicates the number of musicians in the list (which is also the length // of the musicians' array). 5 pts. // // Dynamically allocate an array of musician objects. The array should be // the exact length needed to read the file. 10 pts. // // Use a for-loop to load the array with the content from the text file. 15 pts. // // Close the text file when you are done with it. 5 pts.

// TODO: Open the file writer.txt. Print an error message and exit // the program if the file cannot be opened. 5 pts.

// TODO: Read the number at the beginning of the text file. That number // indicates the number of writers in the list (which is also the length // of the writers' array). 5 pts. // // Dynamically allocate an array of writer objects. The array should be // the exact length needed to read the file. 10 pts. // // Use a for-loop to load the array with the content from the text file. 15 pts. // // Close the text file when you are done with it. 5 pts.

// TODO: Loop through the musicians' array and print all of its data. // Then loop through the writers' array and print all of its data. 15 pts. // Remember to release all dynamically allocated memory before exiting. 5 pts.

return 0; }

Submission: Upload to Canvas and submit your modified Lab09.cpp file. To receive credit for this in-class lab, please remember to sign todays attendance record. After submitting, download and review your file to ensure youve uploaded what you intended. Thank you

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_2

Step: 3

blur-text-image_3

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

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions