Assignment 5 (EXTRA CREDIT)

Due: 11:59 PM Wednesday, June 14



Introduction

This assignment is NOT REQUIRED and is extra credit. Because of this, it might be somewhat more difficult than other assignments you've done. It will be graded on a works/doesn't basis (there is no partial credit). If you don't feel you might not be able to finish it in time, then it's probably best not to start it and spend your time studying for the final instead.


In this assignment you will be using inheritance and virtual functions. The concept of the assignment is to emulate C++ types generically. For example, you should have a base class that represents a generic type. Then for each required type you should derive a class from the "Type" class to handle the specific type. The required types are word, int, double, and sentence. The type class should be able to set the value to something, and also print the value to the screen.

Write a program that reads input from standard input. The format of the input is basically pairs of types followed by values. For example:

     12
     int 5
     double 5.6
     word Hello
     sentence Hello World
     int 6 int 7 int 8
     double 9.1 double 9.2 double 9.3
     word OneWord sentence Many Words are read up to the end of the line.

The first number is the number of type/value pairs. Notice that there can be more than one pair per line so it is not advisable to read in the data one line at a time. In the special case of the "sentence" type, you should read any remaining words to the end of the line.

Your program needs to dynamically allocate an array of pointers to the base class (i.e. The "Type" class). Your program should then proceed to read from the file. For each type/value pair that you read, create a new object of that type and add it to the array. After you finish adding them to the array, go through the array and print out all the values. Here is a test file to try your program on. You can try it out by typing this in linux:

cat as5test.txt | yourProgramName
Your program should output:
5
5.6
Hello
Hello World
6
7
8
9.1
9.2
9.3
oneword
Many words should be read.

Remember that this assignment is graded on a works/doesn't work basis. Make sure you use virtual functions and an array of pointers to the base class. Also make sure you don't read from a file and DO NOT PROMPT for any information, just read it from standard input and assume it is correct. I want to be able to test these quickly so if it doesn't meet the specs it will get 0 credit (that's why I give you the input file I will be using along with the expected output). Don't assume I am dumb and try to make a program that just cout's the required output. I will look at the code. Good luck.