[Solved] ENSF614 Lab 4

$25

File Name: ENSF614_Lab_4.zip
File Size: 122.46 KB

SKU: [Solved] ENSF614 Lab 4 Category: Tag:
5/5 - (1 vote)

Notes:

  • In this lab also you can work with a partner.
  • This is another important lab assignment, and it is aimed to help you understanding very essential topics such as dynamic allocation of memory in C++, and concepts such as copying objects in C++.
  • Material on exercises B and C will be discussed during the lecture on Oct 13 and 15.

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. Its your job to write this file.

What to Submit:

Submit your file MyArray.cppand your program output as part of your lab report

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

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

A B C D
E F G H
I J K L
M N O P
Q R S T

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:

A E I M Q
B F J N R
C G K O S
D H L P T

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 programs 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

Here is the functions prototype and interface comment:

void print_from_binary(char* filename);

/* PROMISES: uses ifstream library object to open the binary file named

  • filename, reads the content of the file which are objects of struct City
  • (one record at a time), and displays them on the screen. It also saves the records
  • into a text-file that its name must be filename argument, but with the extension of .txt

*/

What to Submit:

Submit the definition of your function print_from_binary and the content or the generated text file, as part of your lab report in PDF format.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] ENSF614 Lab 4[Solved] ENSF614 Lab 4
$25