1.0 Overview Pointers, Structures, and Classes are the building block of every p
ID: 3627867 • Letter: 1
Question
1.0 OverviewPointers, Structures, and Classes are the building block of every piece of software written in C/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, ' ') 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) Wednesday, June 15.
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 Wednesday, June 15.
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, June 22.
4.0 Period of Performance
The period of performance of this assignment is 17 days from the date of assignment. Only under special circumstances will any deliverables be accepted after 30 days from the date of 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 < 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.
Explanation / Answer
All programming languages have some primitive building blocks for the description of data and the processes or transformations applied to them (like the addition of two numbers or the selection of an item from a collection). These primitives are defined by syntactic and semantic rules which describe their structure and meaning respectively. [edit]Syntax Parse tree of Python code with inset tokenization Syntax highlighting is often used to aid programmers in recognizing elements of source code. The language above is Python. Main article: Syntax (programming languages) A programming language's surface form is known as its syntax. Most programming languages are purely textual; they use sequences of text including words, numbers, and punctuation, much like written natural languages. On the other hand, there are some programming languages which are more graphical in nature, using visual relationships between symbols to specify a program. The syntax of a language describes the possible combinations of symbols that form a syntactically correct program. The meaning given to a combination of symbols is handled by semantics (either formal or hard-coded in a reference implementation). Since most languages are textual, this article discusses textual syntax. Programming language syntax is usually defined using a combination of regular expressions (for lexical structure) and Backus–Naur Form (for grammatical structure). Below is a simple grammar, based on Lisp: expression ::= atom | list atom ::= number | symbol number ::= [+-]?['0'-'9']+ symbol ::= ['A'-'Z''a'-'z'].* list ::= '(' expression* ')' This grammar specifies the following: an expression is either an atom or a list; an atom is either a number or a symbol; a number is an unbroken sequence of one or more decimal digits, optionally preceded by a plus or minus sign; a symbol is a letter followed by zero or more of any characters (excluding whitespace); and a list is a matched pair of parentheses, with zero or more expressions inside it.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.