Lab 9

Computer Architecture I ShanghaiTech University
Lab 8 Lab 9 Lab 10

Goals

Exercises

Download the files for Lab 9 first.

Exercise 1: C++ warm up

C++ syntax is very similar to C. Almost every C program can compile under C++ compiler. This exercise helps you walk through basis of compiling a C++ program.

First compile hello.cpp using:

$ g++ -Wall -Wextra hello.cpp -o hello
It is always a good practice to compile C/C++ code with -Wall -Wextra flag.

Check-off

Show your TA that you are able to compile and run the code.

Exercise 2: Object Oriented Programming

One of the features that distinguishes C++ from C is classes. In this exercise, we are going to write a simple class.

Check-off

Finish the implementation of class Int in object.cpp, which should have: Show TA your program's output.

Exercise 3: Template Metaprogramming

We can use macro in C to write generic functions. However, macros are very horrible due to its implementation. In C++, we can use templates to solve this problem. In this exercise, you should implement generic functions using templates.

Check-off

Finish the implementation of mul and max in template.cpp. Show TA your program's result.