[SOLVED] COEN244 Assignment 4 –File Processing

35.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon AS4-File-Processing-xxdb2b.zip (230.8 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
5/5 - (1 vote)

 

Q1.  Assume the information of all the TAs of ECE department is stored in a file that is called TAs.txt. In order to be eligible for the TA position, a student should currently registered and can not be an alumni. However the file is corrupted and includes some records of TAs who are already graduated and are not allowed to work as a TA. The format of the record of each TA on the file is as follows:

Student_Id First_Name Last_Name Hire_Year Classification(Grad or Alum) number_of_working_hours

First line of the file shows the total number of students records (max number of records is 100).

a) You need to write a program that reads the file information, removes the lines with the invalid TAs (those who have Alum as the value for classification) and updates the original file.

Here is an example:

TAs.txt
5
19577 sarah lee 2018 Grad 20 40087 peter johnson 2018 Grad 35 22136 rayan lee 2017 Alum 40 40143 ahmed mobarak 2019 Grad 36 40221 rafel Niro 2018 Alum 24

—————————————————————-

TAs.txt After Correction:
3
19577 sarah lee 2018 Grad 20 40087 peter johnson 2018 Grad 35 40143 ahmed mobarak 2019 Grad 36

Hint: You can create an array of TA objects when you open the original TAs.txt file and read the information of TAs.

b) You need to implement a function AddnewTA() that prompt the user for the information of one TA. The user is expected to enter the Student_Id followed by the rest of information. The new TA should be added to the TAs.txt file. Please note that if the user enters a duplicate Student_Id (already existed in the file), the program should reject the input and keep looping until the user enters a non-existing ID.

Please not that your program should handle the exceptions if the user tries to enter information of the unexpected type.

Q2.

Assume class electronic_device stores the information of an electronic device with these attribute: Barnd (string), serial_number (int), color (string), price (double). The class has a virtual function member print().

  • The class cellphone is derived from the electronic_device and has one extra attribute number_of_cameras (int).
  • The class smartwatch is derived from electronic_device and has one extra attribute, battery_life (int).
  • The class laptop is derived form the electronic_device and has two extra attributes: number_of_cores (int) and touchscreen(bool (0 or 1))
  1. a)  Implement the above classes with the needed setter/getter functions. Print() function in each class should display data members of the object.
  2. b)  In the main program, create an array of base class pointers. Then create a set of objects from different derived classes using dynamic memory allocation and store them in the array of base class pointers.
  3. c)  Create a sequential file called information.txt and read the objects stored in the array of base class pointers one by one, determine class of each object’s class name and store these objects in that file. An object will be stored in the file by writing the type of object and the values of its data members, with single space between the fields. An example storage of the objects in the file is given below:

Field 1 Field 2 Field 3 Field 4 Field 5 Field 6 Field 7

cellphone

Apple

110002

blue

1000

3

laptop

Dell

22342

black

800.5

5

0

smartwatch

Samsung

123456

gray

600

24

laptop

Lenovo

23345

black

1000

7

1

smartwatch

Apple

2324395

gray

800

36

cellphone

LG

345522

silver

650

1

3/3

  • AS4-File-Processing-xxdb2b.zip