---
tags: 2023 OOP
---
# 2023 OOP - Homework 2
* Deadline: 11/3 - 14:00
* Upload your homework to moodle platfarm.
* Please consult with TA if you have any question.
* FB or Email



## Problem 1 (30%)
Work on the following practice for interface and implementation.
### Step 0:
Make sure you have installed "Microsoft Visual C++ 2010 Express Edition" or the newer version.
* Step 1: <br> Generate a directory as the vendor side containing GradeBook.h (Fig. 16.11 in your textbook) and GradeBook.cpp (Fig. 16.12 in your textbook), where one assumes that the vendor has "GradeBook.h" as the interface file and "GradeBook.cpp" as the implementation file.
* Step 2: <br> Generate a directory as the client side containing GradeBook.h (Fig. 16.11 in your textbook) and fig16_13.cpp (Fig. 16.13), where "GradeBook.h" is the interface file offered by the vendor and fig16_13.cpp represents the code written by the client. (Note: Step 1 and 2 thus simulate the situation where the client doesn’t know what the implementations are in GradeBook.cpp.)
* Step 3: <br> In the Windows Start menu, go to "Microsoft Visual C++ 2010 Express Edition". Then go to “Visual Studio Command Prompt (2010)”. <br> By this you can open a Visual Studio command prompt. (Note: this is somewhat different from the regular Dos Command prompt. As you shall see, some commands of Visual C++ can only be used in the Visual Studio command prompt
* Step 4: <br> In the Visual Studio command prompt, change your directory to the vendor’s directory, then type. <br> <br>```cl /c /EHsc GradBook.cpp```
Then this generates GradeBook.obj
* Step 5: <br> Copy this GradeBook.obj to the client directory that contains "fig16_13.cpp" and "GradeBook.h".
And in the "Visual Studio Command Prompt (2010)", change to this directory. Then in this prompt, type.
```cl /c /EHsc fig16_13.cpp```
This generates fig16_13.obj.
Then to generate the executable, type.
```link GradeBook.obj fig16_13.obj /out:fig16_13.exe ```
:::warning
**You don’t have to use Visual Studio 2010 !!**
**You can do any approach to generate the files(.h, .cpp, .obj).**
:::
You can then run fig16_13.exe
(Note: Step 5 above simulates the situation where the software vendor sold to the client the interface file and the object code, in order to hide the implementation details in GradeBook.cpp. So essentially the client won’t have any knowledge about the internal implementation of the functions of the GradeBook class.)
For this problem, follow the steps above to generate two folders, named “vendor” and “client”, where the vendor folder should contain the files (.h, .cpp, .obj), and the client folder should contain the files (.h, .cpp, .obj, .exe) designated as above. Put these files in to a folder named Problem1.
:::info
* Write the pramgram of **vendor** part.(12%)
* Write the pramgram of **client** part.(12%)
* Put the screenshot of the output result in Report.doc.(3%)
* Put the files(.h, .cpp, .obj) in Problem1.(3%)
:::
## Problem 2 (30%)
Work in Exercise 16.11, p657 of the textbook.
Modify class GradeBook(Figs.16.11-16.12) as follows requirements:
* Include a second string data member that represents the course instructor's name.
* Provide a *set* function to change the instructor's name and a get function to retrieve it.
* Modify the consructor to specify course name and instructor name parameters.
* Modify function displayMessage to output the welcome message and course name, then the string "This course is presented by: " followed by the instructor's name.
Use your modified class in a test program that demonstrates the class's new capabilities.
For this problem, put these files (.h, .cpp, .obj, .exe) into the folder named Problem2.
:::info
* Write the program of requirement.(6% ea)
* Put the screenshot of the output result in Report.doc.(3%)
* Put the files(.h, .cpp, .obj) in Problem2.(3%)
:::
## Problem 3 (30%)
Work in Exercise 16.15, p657-658 of the textbook.
Create a class called **Date** that includes three pieces of information as data members -- a month (type int), a day (type int) and a year (type int). Your class should have a constructor with three parameters that uses the parameters to initialize the three data members.
For the purpose of this exercise, assume that the values provided for the year and day are correct, but ensure that the month value is in the range 1-12; if it isn't, set the month to 1. Provide a **set** and a **get** function for each data member. Provide a member function **displayDate** that displays the month, day and year separtated by forward slashes(/). Write a test program that demonstrates class **Date's** capabilities.
For this problem, put these files (.h, .cpp, .obj, .exe) into the folder named Problem3.
:::info
* Write the class **Date** and implement the function in it.(18% ea)
* Write a test program.(6%)
* Put the screenshot of the output result in Report.doc.(3%)
* Put the files(.h, .cpp, .obj) in Problem2.(3%)
:::
## Thought (10%)
Please write down your thoughts on homework in Report.doc. You can write what problem you face and how to solve it, or anything you want to say about this howework2.
## Note
Compress all the files (including your report and source code files), and name the compressed file as ```A1115500_hw2.zip(or .rar)``` using your student ID. Then upload the compressed file to the **moodle** platform.
The file structure should be like following forms:
```
|-A1115500_hw2.zip (.rar)
| | p1
| | | client
| | | | your files(.h, .cpp, .obj)
| | | vendor
| | | | your files(.h, .cpp, .obj)
| | p2
| | | your files(.h, .cpp, .obj)
| | p3
| | | your files(.h, .cpp, .obj)
| |-Report.pdf
| |-(And other files...)
```
or
```
|-A1115500_hw2.zip (.rar)
| |-A1105500 (Folder)
| | | Problem1
| | | | client
| | | | | your files(.h, .cpp, .obj)
| | | | vendor
| | | | | your files(.h, .cpp, .obj)
| | | Problem2
| | | | your files(.h, .cpp, .obj)
| | | Problem3
| | | | your files(.h, .cpp, .obj)
| | |-Report.pdf
| | |-(And other files...)
```
**Don't cheating**, or you will get 0 for this homework. If you can’t finish this homework before deadline, just hand in your unfinished code and report.
**Be honest with yourself.**