Starting from:

$25

ENSF614 - A4-GH-JK - Solved

Exercise A: Design a Dynamic Array Class 

 

Read This First: 

 

This exercise is designed to give you some insight about a resizable array class. It also shows other feature of C++ including proper way of copying objects of this class.

 

What to do: 

 

Download files in the files MyArray.h and lab4ExA.cpp. Then read the file MyArray.h, which tells you what the MyArray class interface is and what the member variables are. Pay close attention to the comment that describes the memory management strategy for the MyArray class.  

Read the file lab4ExA.cpp, which demonstrates how a MyArray object could be used.  The file MyArray.cpp is missing. It's your job to write this file.  

 


 

Exercise B: Using C++ library classes, vector and string 

The objective of this exercise is to gain some experience in understanding the C++ library classes, vector, and string.  

What to Do: 

 

Download the files lab4ExB.cpp from D2L.  In this file there is a declaration of vector <string>.  If you compile and run this program it creates the following output:

ABCD 

EFGH 

IJKL 

MNOP 

QRST  

                                                                                                                                                                     1 

Let’s visualize this output as a matrix of letters (5 rows and 4 columns):





















Your job is to complete the definition of the function called transpose that creates a new object of vector<string> where its strings are the transpose of the original vector:





















To test your program, you can change the values of the constants ROWS and COLS, in the main function to make sure your function works with other sizes of the String_Vector. 

What to Submit: 

Submit the definition of your function transpose and the program’s output.

Exercise C: C++ File I/O 

 The objective of this exercise is to help you understanding the basics of file I/O in C++.  

 

What to Do: 

 

Download the files lab4ExC.cpp from D2L. If you read this file carefully you will realize that this simple C++ program creates a binary file (for example: cities.bin), that contain several records of type struct City. 

Each record has two double types represent x and y coordinates of a city on Cartesian Plan, followed by the name of the city, which is stored as a C-string in an array of characters with 30 elements. The program has several functions, the implementation of one of them, called print_from_binary, is missing. Your task will be to write the definition of the missing function. This function is supposed to read the content of the binary file created by the program, and display the its content (records both on the screen and into a text file, using in the following format: 

Name: Calgary, x coordinate: 100, y coordinate: 50  

 

More products