CS1044: Programming with C++

Virginia Tech Computer Science Department
Tom Plunkett
tplunket@csgrad.cs.vt.edu

Home Work Assignment #3: Modify an Existing Software Program and short answer questions

Existing Software Program: Program using an Array of Objects

Savitch P.560-566, Display 9.15 Software Code

(short answer questions below the programming assignment)

Requirements

Due Date: Please email all deliverables to me by 7:00PM, Thursday, June 24.

Overview: Our users want several enhancements to the existing program.

1)Instead of the amounts of money being read in and written out to the screen, the inputs and outputs will go to files. The user will enter the names of the input and output files.

2) The input file will contain at most ten amounts of money, so the array of objects of class Money should be set to a size of ten. The process of reading in and writing out the amounts of money should be able to handle any number of amounts found within the input file.

3) The main function should be modified to allow the user to run additional input files after the first is processed. You may not modify the class Money.

4) Deliverables to be submitted include: source code file, test case input and output files, and a ms word file describing details of your modification process.

5) Please insert all appropriate comments into your source code.

6) You should list the following items in your description of the time spent on this project and the class in general:

a) Time spent planning your code change

b) Time spent modifying the code

c)Time spent testing the code

d)Time spent writing up your results

e)Time spent on reading the textbook (for the week)

f)Time spent on doing problems in the book and working through examples in the book with a compiler (for the week)

7) Your documentation should list all functions in the program and your justification for modifying them or not modifying them.

8) You should also list other alternative methods to modify the code and why you chose against them.

9) Please also mention any unresolved difficulties you encountered in modifying the software code or reading the textbook. A resolved difficulty is one where you ran into something while working on a task and later found out how it works. An unresolved difficulty is where you ran into a problem and avoided the subject matter to complete the task.

10) What is the output from the following code and explain why it is produced?
   

int *p1, *p2, A[100], i, index;
    i=57;
    A[0] = 51;
    A[1] = 107;
    A[2] = 100;
    p2 = &i;
    p1=A;
    index=0;
    cout << *p1 <<endl;
    cout <<p1[index] <<endl;
    cout <<*p2 <<endl;
    index++;
    p2 = new int;
    cout << *p1 <<endl;
    cout << p1[index]<<endl;
    cout << *p2<<endl;
 

11) What is the output produced by the following code and explain why it is produced?

//Type Definitions

struct Bag
{
    double size[20];
    int count;
    Bag *next;
    Bag *previous;
};
typedef Bag* BagPtr;

BagPtr head, tail, current;
head=new Bag;
tail=new Bag;
head->next=tail;
head->previous=NULL;
head->size[0]=100.00;
(*head).count=0;
tail->previous=head;
tail->next=NULL;
(*tail).count=(head->count)++;
current=tail->previous;
tail->size[0]=50.0;
cout << current->count<<endl;
cout << tail->count<<endl;
cout << (*current->next).size[0]<<endl;
cout << (*current->previous).size[0]<<endl;