Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

COP3014-Foundations of Computer Science Assignment #8 ALWAYS COMPLETE AND SUBMIT A PROGRAM EVEN IF IT WILL BE LATE! Objectives: 1. Read the contents of a

COP3014-Foundations of Computer Science Assignment #8

ALWAYS COMPLETE AND SUBMIT A PROGRAM EVEN IF IT WILL BE LATE!

Objectives:

1. Read the contents of a data file one record at a time in a dynamic array; 2. Process the data that was read from the data file one record at a time, into a dynamic array;

Print the records in a dynamic array to a datafile using an ofstream object;

Use the operator new to allocate memory for a dynamic array;

Use the operator delete to de-allocate the memory allocated by the new;

(basically, making previously used memory available for use again)

Copy the content of one dynamic array into another dynamic array

(basically, copying memory from one location to another)

Be able to use the fstream library;

Be able to use a dynamic array of record records;

Be able to use an ifstream object;

Be able to use an ofstream object;

This assignment is an extension of Programming Assignment 3. You will implement a program to manage a dynamic array of call records called "call_stats5.cpp". I have provide the driver call_stats5.cpp to help you implement this program.

Your input data will be in the file callstats_data.txt.

The descriptions of the functions you will implement are as follows:

Initialize is a void function that has three output formal parameters; a

dynamic array of call records called call_DB, an integer called count, and size which is the capacity of the array. Remember, count is the number of records that are being used in the array and it also represents the next available cell in the array where a new item can be stored. The function will read the data from the file callstats_data.txt into the dynamic array call_DB. If call_DB becomes full, the function should call the function Double_Size to double the size (capacity) of call_DB.

Is_empty is a Boolean function that has one input integer parameter, count. count is the number of cells being used. If count == 0 then true is returned; otherwise false is returned.

Is_full is a Boolean function that has two integer input parameters, size and count. If count == size then true is return; otherwise false. The size is the capacity which is the total number of cells allocated to call_DB.

Search is an integer function that has three formal parameters. The array of records, call_DB; the input parameter count; the input parameter key which is the cell phone for the record you are searching for. The function will return the location of key in call_DB if it is there; otherwise -1 is returned.

Add inserts key (cell number) into call_DB. Duplicates cell numbers are ok; add will prompt the user for the firstname, lastname, relays and call length. You may call process record to re-process when you add a new record. The function Add has three output formal parameters; a dynamic array of call records called call_DB, an integer called count, and size which is the capacity of the array.

Remove deletes all records with the cell number stored in key. If duplicate records exist with the same cell number they must all be deleted.

Double_Size doubles the capacity of call_DB. It has three parameter, call_DB, count and size. count is an input parameter and size is an output parameter. First, size is multipled by two; second, memory is allocated using call_record *temp=new call_record[size]; third the records in call_DB are copied into temp with the statement temp[i]=call_DB[i] using a for loop. Forth, the old memory for call_DB is de-allocated using delete [ ] call_DB; Finally, call_DB is set to point to the new memory pointed to by temp using call_DB = temp.

Process has two input parameters: call_DB and count. The function Process will calculate the net cost of a call (net_cost), the tax on a call (call_tax) and the total cost of the call (total_cost) using the number of relay stations (relays) and the length in minutes of the call (call_length) for all call records stored in call_DB. Please consider the following:

The tax rate on a call (call_tax) is simply based on the number of relay stations (relays) used to make the call (0<= relays <=5 then call_tax = 1%; 6<= relays <=11 then call_tax = 3%; 12<= relays<=20 then call_tax = 5%; 21<= relays <=50 then call_tax = 8%; relays >50 then call_tax =12%) .

The net cost of a call is calculated by the following formula: net_cost = ( relays / 50 x 0.40 x call_length).

The tax on a call is equal to net_cost x call_tax / 100.

The total cost of a call (rounded to the nearest hundredth) is calculated by the following formula: total_cost = net_cost + call_tax . All tax and cost calculations should be rounded to the nearest hundredths.

Print has two output parameters, call_DB and count. The function will print every field of every call_record in call_DB to the screen.

Destroy_call_DB has one output parameter call_DB. This function will de-allocate all memory allocated to call_DB. This should be the last function to be called before the program is exited.

Use the driver call_stats5.cpp to help you implement this program.

Output Format for the Function "print":

Consider the following sample output table when designing and implementing the function "print". See section Format of Output below.

(The output is in the following order: firstname, lastname, cell phone number, relays, minutes, net cost, tax rate, call tax, total call cost)

Jean Hayward 9546321555 0 0 0 0.01 0 0

Marlon Brando 5612971340 5 50 2 0.01 0.02 2.02

John Kennedy 3051234567 8 25 1.6 0.03 0.05 1.65

Input Stream:

In the assignment you will declare one ifstream to bind your input to the file "callstats_data.txt" Whenever a program performs file i/o you must include the "fstream" library.

Format of the input data file(input filename is "callstats_data.txt"): Do not include column titles

(The order of the columns are as follows: firstname, lastname, cell phone number, relays, minutes)

Jean Hayward 9546321555 0 0

Marlon Brando 5612971340 5 50

John Kennedy 3051234567 8 25

Hillary Clinton 7542346622 24 17

George Bush 3054432762 15 30

Barack Obama 9544321011 50 100

Donald Trump 8776219988 87 82

Bernie Sanders 9042224556 4 5

Harry Ford 7877176590 11 1

Michelle Obama 5617278899 20 45

Ann Dunham 9546321555 4 3

Vladimir Putin 5612971340 79 86

Harriet Tubman 3051234567 8 25

Oprah Winfrey 5611234444 24 118

Charlotte Ray 3054432762 115 25

Tina Turner 8776219988 265 22

Shirley Chisholm 9042224556 2 5

Maritza Correla 7877176590 89 67

Margaret Thatcher 5617278899 40 56

Format of Output to screen:

(the order of the columns is as follows: firstname, lastname, cell phone number, relays, minutes, net cost, tax rate, call tax, total call cost)

Jean Hayward

9546321555

0

0

0

0.01

0

0

Marlon Brando

5612971340

5

50

2

0.01

0.02

2.02

John Kennedy

3051234567

8

25

1.6

0.03

0.05

1.65

Hillary Clinton

7542346622

24

17

3.26

0.08

0.26

3.53

George Bush

3054432762

15

30

3.6

0.05

0.18

3.78

Barack Obama

9544321011

50

100

40

0.08

3.2

43.2

Donald Trump

8776219988

87

82

57.07

0.12

6.85

63.92

Bernie Sanders

9042224556

4

5

0.16

0.01

0

0.16

Harry Ford

7877176590

11

1

0.09

0.03

0

0.09

Michelle Obama

5617278899

20

45

7.2

0.05

0.36

7.56

Ann Dunham

9546321555

4

3

0.1

0.01

0

0.1

Vladimir Putin

5612971340

79

86

54.35

0.12

6.52

60.87

Harriet Tubman

3051234567

8

25

1.6

0.03

0.05

1.65

Oprah Winfrey

5611234444

24

118

22.66

0.08

1.81

24.47

Charlotte Ray

3054432762

115

25

23

0.12

2.76

25.76

Mary Carter

9544321011

43

10

3.44

0.08

0.28

3.72

Tina Turner

8776219988

265

22

46.64

0.12

5.6

52.24

Shirley Chisholm

9042224556

2

5

0.08

0.01

0

0.08

Maritza Correla

7877176590

89

67

47.7

0.12

5.72

53.43

Margaret Thatcher

5617278899

40

56

17.92

0.08

1.43

19.35

C++ Any spam or wrong asnwers will be Reported otherwise, 5 star and much appreciation :)

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

More Books

Students also viewed these Databases questions

Question

Mobilize your audiences into action through social media messages.

Answered: 1 week ago