Basic Structure
You will be writing a program that parses its command-line arguments, puts the information into a structure that you define, then test the effects of various parameter-passing models on data. You will also be doing simple pointer manipulation.
At the bottom of this page is a rough template for your program: copy it as your starting point. A quick outline of what your program will do:
- Define the "Record" struct, outside of main()
- Declare a local variable "myRec", of type "Record"
- Call MungeRecord, then print out the effect on myRec
- Call MungeRecordForReal, then print out the effect on myRec
- Call MungeRecordFail, then print out the effect on myRec
We will be fleshing the main function out in subsequent steps.
Use the following as the starting skeleton for your program:
#include <iostream>
#include <stdlib> // This defines the library for atoi()
// ADD #include's HERE FOR ANY OTHER LIBRARIES YOU USE
using namespace std;
// ADD ANY GLOBAL CONSTANTS HERE
// STEP 1: ADD YOUR "Record" STRUCTURE DEFINITION HERE
int main(int argc, char *argv[]) {
// STEP 2: DECLARE A LOCAL VARIABLE "myRec" HERE, OF TYPE "Record"
// INITIALIZE THE MEMBERS FROM argv[] ELEMENTS
// STEP 3: WRITE THE FUNCTION MungeRecord() DOWN BELOW, AFTER main().
// ADD CALL TO MungeRecord() HERE, PASSING IN myRec AS ARGUMENT
// AFTER IT RETURNS, PRINT OUT THE CONTENTS OF myRec
// STEP 4: WRITE THE FUNCTION MungeRecordForReal() DOWN BELOW, AFTER main().
// ADD CALL TO MungeRecordForReal() HERE, PASSING IN myRec AS ARGUMENT
// AFTER IT RETURNS, PRINT OUT THE CONTENTS OF myRec
// (Step 4 can be done by just cutting-and-pasting Step 3 above, then
// editing it slightly)
// STEP 5: WRITE THE FUNCTION MungeRecordFail() DOWN BELOW, AFTER main().
// ADD CALL TO MungeRecordFail() HERE, PASSING IN myRec AS ARGUMENT
// AFTER IT RETURNS, PRINT OUT THE CONTENTS OF myRec
// (Again, can just cut-and-paste from Step 3 above, then
// edit it slightly)
return 0;
}
//
// NOW, ADD YOUR OTHER FUNCTIONS HERE
// (Do not put it ABOVE main()! )
//