In this lab, we are going to design an event query system for visitors to check events held by different Schools and Departments for the HKUST 30th Anniversary! To do that, we will use C++ Namespaces. We will define a namespace for each School or Department, which contains some necessary variables and functions. We will implement a function to let the users select interested School or Department, and then call the correct function to list available events according to the user inputs.
We will finish this task based on a skeleton code provided in source files. Before getting started, please read the Namespace Lecture Notes.
In this lab, we have six namespaces:
engineering
(Denote the School of Engineering).cse
(Denote the Department of CSE).ece
(Denote the Department of ECE).science
(Denote the School of Science).math
(Denote the School of Mathematics).physics
(Denote the School of Physics).engineering
namespace and nested namespaces cse
, ece
(in school-namespaces.h
):
namespace engineering { void show_events(); namespace cse { extern std::string events[]; void show_events(); } namespace ece { extern std::string events[]; void show_events(); } }Note: the
extern
keyword used in the above code means we only declare the events
variable in this head file, and will define it in other places.
For more usages, please refer to extern.
science
namespace and nested namespaces math
, physics
(in school-namespaces.h
):
namespace science { void show_events(); extern std::string events[]; namespace math { extern std::string events[]; void show_events(); } namespace physics { extern std::string events[]; void show_events(); } }
events
variables and the body of show_events
functions are defined in in school-namespaces.cpp
.
For example, the events of the Department of CSE and the Department of ECE are respectively defined as follows:
school-namespaces.cpp
):
string events[] { "9:00 Making Machine Learning Automated and Trustworthy.", "11:00 The Next Frontier in Type Inference.", "14:00 AI-Human Teaming for Decision Making." };
school-namespaces.cpp
):
string events[] { "15:00 2D Materials, from Academia to Industry.", "16:00 Bridging Vision and Language for Cross-Modal Understanding and Generation." };
events-query.cpp
, which asks the users to select the interested Department or School, and call the
correct show_events
function as defined in school-namespaces.cpp
. We have provided most parts of the code, you need to fill in the gaps
to speficy namespaces and call the corresponding printing functions:
events-query.cpp
):
#include#include "school-namespaces.h" // Note: You are supposed to insert new lines in this file, but not modify/delete existing lines! // TODO 1: Specify namespaces to be used in this file. void QueryEvents() { cout << "Select the school: 1. School of Engineering; 2. School of Science:"; char choice; while(cin >> choice) { if (choice == '1' || choice == '2') break; else cout << "Select from 1 or 2." << endl; } if(choice == '1') { cout << "Select the department: 1. Department of CSE; 2. Department of ECE; 3. All Departments:"; // TODO 2: Call the corresponding show_events function according to input. } else { cout << "Select the department: 1. Department of Mathematics; 2. Department of Physics; 3. All Departments:"; // TODO 3: Call the corresponding show_events function according to input. } }
school-namespaces.cpp
.
events
variables and show_events
functions to eliminate ambiguities.show_events
for the School of Engineering. Note that in this function, you need to print
out events of both the CSE and ECE Departments.show_events
for the School of Science. Note that the School of Science has events independent
of departments. In this function, you need to print out events of the School and events of both the Mathematics and Physics Departments.events-query.cpp
(You should only insert new lines to this file, but not modify/delete existing lines!).
3. ALL
means printing all events of the school. make
to build the executable (i.e., main.exe
).
main.exe
, check with the input selections and expected output below (inputs are in red):Welcome to 30th Anniversary of HKUST! Check Events by Department: Select the school: 1. School of Engineering; 2. School of Science:1 Select the department: 1. Department of CSE; 2. Department of ECE; 3. All Departments:1 Welcome to Department of CSE! 9:00 Making Machine Learning Automated and Trustworthy. 11:00 The Next Frontier in Type Inference. 14:00 AI-Human Teaming for Decision Making.
Welcome to 30th Anniversary of HKUST! Check Events by Department: Select the school: 1. School of Engineering; 2. School of Science:1 Select the department: 1. Department of CSE; 2. Department of ECE; 3. All Departments:2 Welcome to Department of ECE! 15:00 2D Materials, from Academia to Industry. 16:00 Bridging Vision and Language for Cross-Modal Understanding and Generation.
Welcome to 30th Anniversary of HKUST! Check Events by Department: Select the school: 1. School of Engineering; 2. School of Science:1 Select the department: 1. Department of CSE; 2. Department of ECE; 3. All Departments:3 Welcome to School of Engineering! 9:00 Making Machine Learning Automated and Trustworthy. 11:00 The Next Frontier in Type Inference. 14:00 AI-Human Teaming for Decision Making. 15:00 2D Materials, from Academia to Industry. 16:00 Bridging Vision and Language for Cross-Modal Understanding and Generation.
Welcome to 30th Anniversary of HKUST! Check Events by Department: Select the school: 1. School of Engineering; 2. School of Science:1 Select the department: 1. Department of CSE; 2. Department of ECE; 3. All Departments:4 Invalid input.
Welcome to 30th Anniversary of HKUST! Check Events by Department: Select the school: 1. School of Engineering; 2. School of Science:2 Select the department: 1. Department of Mathematics; 2. Department of Physics; 3. All Departments:1 Welcome to Department of Mathematics! 16:00 Rate of blow up in the thin obstacle problem.
Welcome to 30th Anniversary of HKUST! Check Events by Department: Select the school: 1. School of Engineering; 2. School of Science:2 Select the department: 1. Department of Mathematics; 2. Department of Physics; 3. All Departments:2 Welcome to Department of Physics! 11:00 Interfacial Dynamics between a Hydrogel and a Fluid: Modeling and Simulation. 14:00 Application of Flow Model to Theoretical Physics.
Welcome to 30th Anniversary of HKUST! Check Events by Department: Select the school: 1. School of Engineering; 2. School of Science:2 Select the department: 1. Department of Mathematics; 2. Department of Physics; 3. All Departments:3 Welcome to School of Science! 10:00 A variational approach to describe the moduli space of minimal immersions in hyperbolic. 16:00 Rate of blow up in the thin obstacle problem. 11:00 Interfacial Dynamics between a Hydrogel and a Fluid: Modeling and Simulation. 14:00 Application of Flow Model to Theoretical Physics.
The due date and time will be 10-min after your lab session. You are supposed to upload the following files in an archive to ZINC:
- school-namespaces.cpp - events-query.cppYou can submit your codes multiple times by the deadline. Only the last submission will be graded.