CS115 Exercise: C++ Pointers

Introduction

In this exercise you will expand on a program by using the reference, and dereference operators to pass a structure instance by reference to a function and manipulate it. You will also create a dynamic array for associated data.

Instructions

Part 1 - Passing pointers to functions

At this point, your output should look something like this:

Please enter a name:  Sam
Please enter an id:  195556
Please enter a mark: 87
Please enter a mark: 88
Please enter a mark: 89
Student info: 
Name: Sam
Id: 195556
Mark 0: 87
Mark 1: 88
Mark 2: 89

Part 2 - Making and Using Dynamically Allocated Arrays.

Let us say that you want to choose how many marks to enter for the student and have the array change size accordingly. This gives you the opportunity to work with dynamic pointers.

You will have to make the following changes to your code:

The run might look like the following:
 How many marks are there? 5
Please enter a name:  Sam
Please enter an id:  195556
Please enter a mark: 87
Please enter a mark: 98
Please enter a mark: 77
Please enter a mark: 88
Please enter a mark: 78
Student info: 
Name: Sam
Id: 195556
Mark 0: 87
Mark 1: 98
Mark 2: 77
Mark 3: 88
Mark 4: 78

Part 3 (Just for Fun) - Dynamically Allocated Arrays of Structures


This page last modified:
Tuesday, 08-Nov-2011 00:17:25 CST

CS Dept Home Page
CS Dept Class Files
CS115 Lab Files

Copyright: Department of Computer Science, University of Regina.