Timing and general instructions
You have 1 hour 50 minutes to complete the programming part of the final exam. This is a closed notes exam so you should not open any website other than the Titanium exam page. Do not communicate with your classmates or look at their screens. Direct all your questions to the instructor or lab assistant only.
You are allowed to view your own study guide and use paper for scratch work that will be provided for you.
You are free to use any editor and the command line on Tuffix to write, compile, and test your program. The instructors will use clang++
to check your programs so make sure your code works with that compiler.
You are expected to have used the programming environment during our lab sessions so instructors and lab assistants will not answer questions regarding interpretting syntax errors or debugging code.
Problem and points
There are three programming problems that you need to complete.
- Courses (15 points)
- Organization (25 points)
- Student (10 points)
Submission
Your answers will be submitted through GitHub. You can push your code as many times as you want before the end of the final exam. We will check the last version that you pushed.
When you are done, verify you have pushed your code properly on GitHub. Simply refresh your GitHub repo and click on the individual files to see if they have been changed.
On Titanium, click on the Add submission
button in the midterms page. Provide the URL for your GitHub repo containing the final exam and click on Save changes
. Finally click on Submit assignment
.
Before leaving the room, please approach the instructor who will verify that you submitted your exam properly. Also turn in your scratch paper and study guide to the instructor.
Course Registration
Course
Implement the class named Course
which has the private variables (data members) int course_num_
, std::string course_name_
, and std::string department_
.
Please note that the course_name_
and department_
are of arbitrary length and can contain spaces (i.e. Computer Science). Include accessor and mutator functions for each variable (data member).
Create an overload constructor (nondefault constructor) that takes in three parameters to set the values for course_num_
, course_name_
, and department_
. Create a default constructor that assigns 121
to course_num_
, "Object oriented programming"
to course_name_
and "Computer Science"
to department_
.
Create a display
member function that shows on screen information about the course. Below is an example of how it might look like:
Course number: 121Course name: Object oriented programmingDepartment: Computer Science
Place your class in course.hpp
. No need to create course.cpp
.
dynamic memory allocation
In the main
function, you are asked to dynamically allocate an array of Course
objects whose size depends on the users input. It will also ask the user to provide values for each course, that you will use to set the values of the Courses
inside your array. Finally, it will ask you to display information about each course added by the user to the screen.
More detailed instructions are found inside main.cpp
.
Code evaluation
Open the terminal and navigate to the folder that contains this problem. Assuming you have pulled the code inside of /home/student/final
and you are currently in /home/student
you can issue the following commands
cd final
You also need to navigate into the problem you want to answer. To access the files needed to answer problem 1, for example, you need to issue the following command.
cd prob01
When you want to answer another problem, you need to go back up to the parent folder and navigate into the next problem. Assuming you are currently in prob01
, you can issue the following commands to go to the parent folder then go into another problem you want to answer; prob02
for example.
cd ..cd prob02
Use the clang++
command to compile your code and the ./
command to run it. The sample code below shows how you would compile code in main.cpp
into the executable file main
. Make sure you use the correct filenames required in this problem. Take note that if you make any changes to your code, you will need to compile it first before you see changes when running it.
clang++ -std=c++17 main.cpp -o main./main
Submission
- When everything runs correctly, lets copy your code into the Github repository. The first step is to add your code to what is called the staging area using gits
add
command. The parameter afteradd
is the name of the file you want to add.git add main.cpp course.hpp
- Once everything is in the staging area, we use the
commit
command to tell git that we have added everything we need into the staging area.git commit
- In case it asks you to configure global variables for an email and name, just copy the commands it provides then replace the dummy text with your email and Github username.
git config --global user.email "[email protected]"git config --global user.name "Tuffy Titan"
When youre done, make sure you type
git commit
again. - Git will ask you to describe what you have added to the staging area. By default, you will use a command-line based editor called nano. Go ahead and provide a description then press Ctrl + x to exit. Press Y to confirm that you want to make changes and then press Enter.
- Lets push all changes to the Github repository using gits
push
command. Provide your Github username and password when you are asked.git push
- When you finish the exercise, go back to Titanium and click on the
Add submission
button in the lab exercise page. Provide a short message in the text area such as finished lab exercise and click onSave changes
. Finally click onSubmit assignment
to inform your instructor that you are done.
5/5 – (1 vote)
Organization Positions
Create a program that stores and manages information about the positions in an organization.
Person
First, create a Person
class that has name, address, and phone number data members.
Create a nondefault constructor that accepts the values that will be assigned to name (std::string
), address (std::string
), and phone number (std::string
) as parameters to the corresponding data members.
Create a default constructor that sets name to "Unidentified"
, address to "Somewhere"
, and phone number to 1-800-000-0000
.
Provide accessors and mutators for all of the class data members.
Create a display
member function that displays information about the Person
on the console. Take note that it does not take any parameters and does not return any value. For example, the default constructor might show the following information on screen:
UnidentifiedSomewhere1-800-000-0000
Organization
Create an Organization
class that has a name, president, vice president and treasurer as data members. The positions president, vice president, and treasurer are all Person
objects.
Create a non-default constructor that accepts a value that will be assigned to the name (std::string
) of the organization.
Create a default constructor that sets name to "Unknown"
.
Create accessors and mutators for all data members (i.e., name, president, vice president and treasurer).
get_position
In the Organization
class, create a get_position
member function that accepts a name (std::string
) parameter. The member function will check whether the name provided is the name of the president, vice president or treasurer and return an std::string
describing the position. That means, it will return "president"
, "vice president"
or "treasurer"
. However, if the name is not any of the three positions, it should return "not an officer"
.
Other instructions
Complete the main
function as described in the comments inside the file.
Place your classes in organization.hpp
. Member functions that take more than five lines or use complex constructs should have their function prototype in organization.hpp
and implementation in organization.cpp
.
Code evaluation
Open the terminal and navigate to the folder that contains this problem. Assuming you have pulled the code inside of /home/student/final
and you are currently in /home/student
you can issue the following commands
cd final
You also need to navigate into the problem you want to answer. To access the files needed to answer problem 2, for example, you need to issue the following command.
cd prob02
When you want to answer another problem, you need to go back up to the parent folder and navigate into the next problem. Assuming you are currently in prob02
, you can issue the following commands to go to the parent folder then go into another problem you want to answer; prob03
for example.
cd ..cd prob03
Use the clang++
command to compile your code and the ./
command to run it. The sample code below shows how you would compile code saved inmain.cpp
, and into the executable file main
. Make sure you use the correct filenames required in this problem. Take note that if you make any changes to your code, you will need to compile it first before you see changes when running it.
clang++ -std=c++17 main.cpp organization.cpp -o main./main
Submission
- When everything runs correctly, lets copy your code into the Github repository. The first step is to add your code to what is called the staging area using gits
add
command. The parameter afteradd
is the name of the file you want to add.git add main.cpp organization.hpp organization.cpp
- Once everything is in the staging area, we use the
commit
command to tell git that we have added everything we need into the staging area.git commit
- In case it asks you to configure global variables for an email and name, just copy the commands it provides then replace the dummy text with your email and Github username.
git config --global user.email "[email protected]"git config --global user.name "Tuffy Titan"
When youre done, make sure you type
git commit
again. - Git will ask you to describe what you have added to the staging area. By default, you will use a command-line based editor called nano. Go ahead and provide a description then press Ctrl + x to exit. Press Y to confirm that you want to make changes and then press Enter.
- Lets push all changes to the Github repository using gits
push
command. Provide your Github username and password when you are asked.git push
- When you finish the exam, go back to Titanium and click on the
Add submission
button in the lab exercise page. Provide a short message in the text area such as finished lab exercise and click onSave changes
. Finally click onSubmit assignment
to inform your instructor that you are done.
Student Class
Create a class called Student
which inherits from the Person
class that you created in prob02. The Student
class has the private variables (data members) int student_id_
and std::string major_
.
Create accessors and mutators for all data members in the Student
class. Create a non-default constructor that accepts the following arguments in the given order: std::string name
, std::string address
, std::string phone_num
, int student_id
, std::string major
In the Student
class, override the display
member function to display all information about the student to the console as such:
Joan Smith123 N. Main St. Orange, CA 92874562-744-852412345Computer Science
In the main
function, create a Student
object by calling the non-default constructor with the same information as the example above. Extra points if you use dynamically allocate the Student
object in the heap. Call the display
member function to print information about the student to the console.
You need to create the Student
class inside person.hpp
and modify the main
function inside main.cpp
. You do not need to create other files aside from these two.
Code evaluation
Open the terminal and navigate to the folder that contains this problem. Assuming you have pulled the code inside of /home/student/midterm
and you are currently in /home/student
you can issue the following commands
cd midterm
You also need to navigate into the problem you want to answer. To access the files needed to answer problem 3, for example, you need to issue the following command.
cd prob03
When you want to answer another problem, you need to go back up to the parent folder and navigate into the next problem. Assuming you are currently in prob03
, you can issue the following commands to go to the parent folder then go into another problem you want to answer; prob01
for example.
cd ..cd prob01
Use the clang++
command to compile your code and the ./
command to run it. The sample code below shows how you would compile code saved in main.cpp
, and into the executable file main
. Make sure you use the correct filenames required in this problem. Take note that if you make any changes to your code, you will need to compile it first before you see changes when running it.
clang++ -std=c++17 main.cpp -o main./main
Submission
- When everything runs correctly, lets copy your code into the Github repository. The first step is to add your code to what is called the staging area using gits
add
command. The parameter afteradd
is the name of the file you want to add.git add main.cpp person.hpp
- Once everything is in the staging area, we use the
commit
command to tell git that we have added everything we need into the staging area.git commit
- In case it asks you to configure global variables for an email and name, just copy the commands it provides then replace the dummy text with your email and Github username.
git config --global user.email "[email protected]"git config --global user.name "Tuffy Titan"
When youre done, make sure you type
git commit
again. - Git will ask you to describe what you have added to the staging area. By default, you will use a command-line based editor called nano. Go ahead and provide a description then press Ctrl + x to exit. Press Y to confirm that you want to make changes and then press Enter.
- Lets push all changes to the Github repository using gits
push
command. Provide your Github username and password when you are asked.git push
- When you finish the exercise, go back to Titanium and click on the
Add submission
button in the lab exercise page. Provide a short message in the text area such as finished lab exercise and click onSave changes
. Finally click onSubmit assignment
to inform your instructor that you are done.
Reviews
There are no reviews yet.