If you want to get started on this assignment you will need an understanding of pointers and C++ classes.
You should have had, at least, a brief introduction to this in CS 121. Click on the links below to go to the
pages on pointers and C++ classes for this web site.

Link: Pointers
Link: C++ Classes
         

Programming Assignment 1

Wednesday, September 11


Statement of Work
Programming Assignment 1

1.0 Overview
  Pointers, Structures, and Classes are the building block of every piece of software written in C++. This programming assignment provides a basic introduction to the creation and use of these important program building blocks.

2.0 Requirements
  The student shall define, develop, document, prototype, test, and modify as required the software system.
  2.1 This software system shall consist of one source file (.cpp) and one header file (.h).
    2.2 The header file, to be called Prog1Class.h shall define a data structure and a class.
      2.2.1 The structure type, to be called Prog1Struct shall contain three variables: (1) an int called m_iVal, (2) a double called m_dVal, and (3) a character array called m_sLine capable of holding strings of up to 80 characters in length (don't forget 1 extra character for the null terminator).
      2.2.2 The class, to be called Prog1Class, shall contain the following functions: a constructor and destructor and the functions PtrFunction(), RefFunction() and StructFunction().
    2.3 The .cpp source file, to be called Prog1Class.cpp, shall contain all of the functions required to implement the class. Details of the three functions named in 2.2.2 are given below.
      2.3.1 PtrFunction() This function shall take two arguments: (1) a pointer to an integer, and (2) a pointer to a double. It shall query the user to input at the keyboard values to be stored in the variables referenced by it's pointer arguments.
      2.3.2 RefFunction() This function shall be a C++ Reference function and shall take two arguments: (1) a reference to an integer, and (2) a reference to a double. It shall query the user to input at the keyboard values to be stored in the variables referenced by it's arguments.
      2.3.3 StructFunction() This function shall take a single argument; a pointer to a data structure of the type defined in the header file. It shall query the user to input at the keyboard values to be stored in the three fields of the data structure referenced by it's argument. (Hint: use "cin>>" to input the values for the integer and double, then use cin.getline(char *, array_length, '\n') to input the string.)
    2.4 In order to test the class functions a second source file should be created and used to test all functions in the class. It should contain only the main() function, and should perform the following actions, in the order listed. (Note: This source file will not be turned in. The instructor will use his own test driver.)
      2.4.1 The main() function should define the following variables: (1) an int, (2) a double, (3) a structure of the type defined in the header file, (4) a pointer to a structure of the type defined in the header file, and (5) a pointer to a class of the type defined in the header file.
      2.4.2 The main() function should perform the following dynamic memory allocations: (1) dynamically allocate memory for a data structure of the type defined in the header file using the C++ operator new and set the structure pointer pointing to this structure, (2) dynamically allocate memory for a class of the type defined in the header file (using new)and set the class pointer pointing to it.
      2.4.3 The main() function should perform the following function calls and actions in the order given.
        2.4.3.1 Call the PtrFunction in the class instance passing in the addresses of the int and double variables. Upon return print the values of these variables on the screen and make sure they are correct.
        2.4.3.2 Call the RefFunction in the class instance passing in the int and double variables. Upon return print the values of these variables on the screen and make sure they are correct.
        2.4.3.3 Call the StructFunction in the class instance passing in the address of the structure. Upon return print the values in the fields of the structure and make sure they are correct.
        2.4.3.4 Call the StructFunction in the class instance passing in the structure pointer. Upon return print the values in the fields of the structure pointed to by the structure pointer and make sure they are correct.
  2.5 This program shall be capable of being tested using a text file and I/O redirection. (This will be explained in class.) A copy of a sample test text file is given below.
3.0 Deliverables
  These products shall be delivered electronically via e-mail as specified below to the instructor.
3.1 Software Design Document -- The student shall provide an electronic copy of a software design document following the required format for instructor approval NLT (Not Later Than) Monday, September 23.
3.2 Software Test Plan -- The student shall provide an electronic copy of a software test plan for complete verification and validation of the software for instructor approval NLT Monday, September 23.
3.3 Electronic copies of source code -- The student shall provide electronic copies of the Prog1Class.h and Prog1Class.cpp files for instructor testing. Files should be submitted via e-mail to the instructor. The electronic copies of the source code shall be delivered NLT Wednesday, October 2.
4.0 Period of Performance
  The period of performance of this assignment is 21 days from the date of assignment. Under no circumstances will any deliverables be accepted after the posted Drop Dead Date of the assignment.



We will discuss this programming assignment in class. At that time some suggestions and hints will be presented as to how to implement the assignment.

Sample File:
The following is a sample of the type of text file to be used in testing your program.


1
2.3
3
3.4
4 5.6 Test string 1
6 7.8 Test string 2

Testing with I/O Redirection

Assume that you have created an executable program called Prog1.exe and a text file called test.txt like the sample given above. To test your program using I/O redirection with this text file you would place this file in the same directory as the executable then type the following command at a DOS prompt.

Prog1.exe < test.txt

At each point in your program where an input is expected by the user from the keyboard, the program would instead read a line from the text file. Note that the order of data in the text file MUST be in the exact order as expected by the input statements of the program. There can be no other input statements in the program.

A copy of this test file and a demonstration executable can be found in a zip file here.