Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
IndividualMiniprojectC++/.vscode/
IndividualMiniprojectC++/external_libraries/boost_1_85_0
IndividualMiniprojectC++/external_libraries/boost_1_86_0
IndividualMiniprojectC++/external_libraries/Crow-1.2.0-Darwin
IndividualMiniprojectC++/build/*
!IndividualMiniprojectC++/build/README.txt
!IndividualMiniprojectC++/external_libraries/README.txt
!IndividualMiniprojectC++/external_libraries/README.txt
*.swp
64 changes: 61 additions & 3 deletions IndividualMiniprojectC++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15)

project(IndividualMiniproject)

set(INCLUDE_PATHS external_libraries/boost_1_85_0 external_libraries/Crow-1.2.0-Darwin/include)
set(INCLUDE_PATHS external_libraries/boost_1_86_0 external_libraries/Crow-1.2.0-Darwin/include)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

Expand Down Expand Up @@ -30,7 +30,7 @@ FetchContent_MakeAvailable(googletest)
target_include_directories(IndividualMiniproject PUBLIC
${INCLUDE_PATHS}
include
/opt/homebrew/Cellar/asio/1.30.2/include
# /opt/homebrew/Cellar/asio/1.30.2/include
)

target_link_libraries(IndividualMiniproject PRIVATE
Expand All @@ -44,15 +44,19 @@ enable_testing()
add_executable(IndividualMiniprojectTests
test/sample.cpp
test/CourseUnitTests.cpp
test/DepartmentUnitTests.cpp
test/RouteControllerUnitTests.cpp
src/Course.cpp
src/Department.cpp
src/MyFileDatabase.cpp
src/RouteController.cpp
src/MyApp.cpp
)

target_include_directories(IndividualMiniprojectTests PRIVATE
${INCLUDE_PATHS}
include
/opt/homebrew/Cellar/asio/1.30.2/include
# /opt/homebrew/Cellar/asio/1.30.2/include
)

target_link_libraries(IndividualMiniprojectTests PRIVATE
Expand All @@ -78,6 +82,8 @@ if (CPPLINT)
src/Globals.cpp
test/sample.cpp
test/CourseUnitTests.cpp
test/DepartmentUnitTests.cpp
test/RouteControllerUnitTests.cpp
)

# Custom target to run cpplint
Expand All @@ -90,3 +96,55 @@ if (CPPLINT)
else()
message(WARNING "cpplint not found! Skipping style checks.")
endif()

if (ENABLE_COVERAGE)
# set comiler flags
set(CMAKE_CXX_FLAGS "-O0 -coverage")

# find required tools
find_program(LCOV lcov REQUIRED)
find_program(GENHTML genhtml REQUIRED)

# add coverage target
add_custom_target(
coverage
# gather data
COMMAND ${LCOV} --directory . --capture --output-file coverage.info
# exclude header files
COMMAND ${LCOV} --remove coverage.info '/usr/*' '*.h' '*main.cpp' '*test*' --output-file coverage.info
COMMAND ${LCOV} --remove coverage.info '*MyApp.cpp' --output-file coverage.info
# generate report
COMMAND ${GENHTML} --demangle-cpp -o coverage coverage.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()

add_executable(CodeCoverage
test/sample.cpp
test/CourseUnitTests.cpp
test/DepartmentUnitTests.cpp
test/MyFileDatabaseUnitTests.cpp
test/RouteControllerUnitTests.cpp
src/Course.cpp
src/Department.cpp
src/MyFileDatabase.cpp
src/RouteController.cpp
src/MyApp.cpp
)

target_include_directories(CodeCoverage PRIVATE
${INCLUDE_PATHS}
include
)

target_link_libraries(CodeCoverage PRIVATE
gtest
gtest_main
)

find_program(CPPCHECK cppcheck)
add_custom_target(
cppcheck
#COMMAND ${CPPCHECK} -I ../include/ --enable=all --inconclusive --library=posix --suppress=missingInclude --suppress=missingIncludeSystem --suppress=checkersReport --suppress=unusedFunction ../src/ ../test/
COMMAND ${CPPCHECK} -I ../include/ --enable=all --library=posix --suppress=missingInclude --suppress=missingIncludeSystem --suppress=checkersReport --suppress=unusedFunction ../src/ ../test/
)
17 changes: 17 additions & 0 deletions IndividualMiniprojectC++/build/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,20 @@ make
make cpplint -for style checking

If you ever need to clean up some files make clean is always an option

CODE COVERAGE with LCOV:
The code coverage library requires lcov and genhtml.

Do these in the build directory:

cmake -DENABLE_COVERAGE=true .. && make
./CodeCoverage; make coverage

The first command builds the targets and executables,
the second one generates the report in build/coverage/index.html
that can be viewed in a browser.


STATIC CODE ANALYSIS
Run the following command after running cmake to run static code analysis:
make cppcheck
2 changes: 1 addition & 1 deletion IndividualMiniprojectC++/include/Course.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Course {
std::string courseTimeSlot;

public:
Course(int count, const std::string &instructorName, const std::string &courseLocation, const std::string &timeSlot);
Course(int capacity, const std::string &instructorName, const std::string &courseLocation, const std::string &timeSlot);
Course();

std::string getCourseLocation() const;
Expand Down
6 changes: 3 additions & 3 deletions IndividualMiniprojectC++/include/Department.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Department {
public:
Department(std::string deptCode, std::map<std::string, std::shared_ptr<Course>> courses,
Department(std::string deptCode, const std::map<std::string, std::shared_ptr<Course>>& courses,
std::string departmentChair, int numberOfMajors);

Department();
Expand All @@ -20,8 +20,8 @@ class Department {
void deserialize(std::istream& in);
void addPersonToMajor();
void dropPersonFromMajor();
void addCourse(std::string courseId, std::shared_ptr<Course> course);
void createCourse(std::string courseId, std::string instructorName, std::string courseLocation,
void addCourse(const std::string& courseId, std::shared_ptr<Course> course);
void createCourse(const std::string& courseId, std::string instructorName, std::string courseLocation,
std::string courseTimeSlot, int capacity);
std::string display() const;
std::string getDepartmentChair() const;
Expand Down
1 change: 1 addition & 0 deletions IndividualMiniprojectC++/include/RouteController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class RouteController {
MyFileDatabase* myFileDatabase;

public:
RouteController();
void initRoutes(crow::App<>& app);
void setDatabase(MyFileDatabase* db);

Expand Down
114 changes: 69 additions & 45 deletions IndividualMiniprojectC++/src/Course.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2024 Richard Cruz-Silva
#include "Course.h"
#include <iostream>
#include <string>


/**
* Constructs a new Course object with the given parameters. Initial count starts at 0.
*
Expand All @@ -11,14 +11,19 @@
* @param timeSlot The time slot of the course.
* @param capacity The maximum number of students that can enroll in the course.
*/
Course::Course(int capacity, const std::string& instructorName, const std::string& courseLocation, const std::string& timeSlot)
: enrollmentCapacity(capacity), enrolledStudentCount(500), courseLocation(courseLocation), instructorName(instructorName), courseTimeSlot(timeSlot) {}
Course::Course(int capacity, const std::string& instructorName,
const std::string& courseLocation, const std::string& timeSlot)
: enrollmentCapacity(capacity), enrolledStudentCount(500),
courseLocation(courseLocation), instructorName(instructorName),
courseTimeSlot(timeSlot) {}

/**
* Constructs a default Course object with the default parameters.
*
*/
Course::Course() : enrollmentCapacity(0), enrolledStudentCount(0), courseLocation(""), instructorName(""), courseTimeSlot("") {}
Course::Course() : enrollmentCapacity(0), enrolledStudentCount(0),
courseLocation(""), instructorName(""),
courseTimeSlot("") {}


/**
Expand All @@ -27,8 +32,11 @@ Course::Course() : enrollmentCapacity(0), enrolledStudentCount(0), courseLocatio
* @return true if the student is successfully enrolled, false otherwise.
*/
bool Course::enrollStudent() {
if (enrolledStudentCount < enrollmentCapacity) {
enrolledStudentCount++;
return false;
return true;
}
return false;
}

/**
Expand All @@ -37,81 +45,97 @@ bool Course::enrollStudent() {
* @return true if the student is successfully dropped, false otherwise.
*/
bool Course::dropStudent() {
if (enrolledStudentCount > 0) {
enrolledStudentCount--;
return false;
return true;
}
return false;
}

std::string Course::getCourseLocation() const {
return courseLocation;
return courseLocation;
}

std::string Course::getInstructorName() const {
return courseTimeSlot;
return instructorName;
}

std::string Course::getCourseTimeSlot() const {
return instructorName;
return courseTimeSlot;
}

std::string Course::display() const {
return "\nInstructor: " + instructorName + "; Location: " + courseLocation + "; Time: " + courseTimeSlot;
return "\nInstructor: " + instructorName + "; Location: " +
courseLocation + "; Time: " + courseTimeSlot;
}

void Course::reassignInstructor(const std::string& newInstructorName) {
std::cout << "Old Instructor: " << instructorName << std::endl;
this->instructorName = newInstructorName; // Ensure the class member is being updated
std::cout << "New Instructor: " << this->instructorName << std::endl;
//std::cout << "Old Instructor: " << instructorName << std::endl;
// Ensure the class member is being updated
if (!newInstructorName.empty())
this->instructorName = newInstructorName;
//std::cout << "New Instructor: " << this->instructorName << std::endl;
}

void Course::reassignLocation(const std::string& newLocation) {
if (!newLocation.empty())
courseLocation = newLocation;
}

void Course::reassignTime(const std::string& newTime) {
if (!newTime.empty())
courseTimeSlot = newTime;
}

void Course::setEnrolledStudentCount(int count) {
if (0 <= count)
enrolledStudentCount = count;
}

bool Course::isCourseFull() const {
return enrollmentCapacity > enrolledStudentCount;
return enrollmentCapacity <= enrolledStudentCount;
}

void Course::serialize(std::ostream& out) const {
out.write(reinterpret_cast<const char*>(&enrollmentCapacity), sizeof(enrollmentCapacity));
out.write(reinterpret_cast<const char*>(&enrolledStudentCount), sizeof(enrolledStudentCount));

size_t locationLen = courseLocation.length();
out.write(reinterpret_cast<const char*>(&locationLen), sizeof(locationLen));
out.write(courseLocation.c_str(), locationLen);

size_t instructorLen = instructorName.length();
out.write(reinterpret_cast<const char*>(&instructorLen), sizeof(instructorLen));
out.write(instructorName.c_str(), instructorLen);

size_t timeSlotLen = courseTimeSlot.length();
out.write(reinterpret_cast<const char*>(&timeSlotLen), sizeof(timeSlotLen));
out.write(courseTimeSlot.c_str(), timeSlotLen);
out.write(reinterpret_cast<const char*>(&enrollmentCapacity),
sizeof(enrollmentCapacity));
out.write(reinterpret_cast<const char*>(&enrolledStudentCount),
sizeof(enrolledStudentCount));

size_t locationLen = courseLocation.length();
out.write(reinterpret_cast<const char*>(&locationLen),
sizeof(locationLen));
out.write(courseLocation.c_str(), locationLen);

size_t instructorLen = instructorName.length();
out.write(reinterpret_cast<const char*>(&instructorLen),
sizeof(instructorLen));
out.write(instructorName.c_str(), instructorLen);

size_t timeSlotLen = courseTimeSlot.length();
out.write(reinterpret_cast<const char*>(&timeSlotLen),
sizeof(timeSlotLen));
out.write(courseTimeSlot.c_str(), timeSlotLen);
}

void Course::deserialize(std::istream& in) {
in.read(reinterpret_cast<char*>(&enrollmentCapacity), sizeof(enrollmentCapacity));
in.read(reinterpret_cast<char*>(&enrolledStudentCount), sizeof(enrolledStudentCount));

size_t locationLen;
in.read(reinterpret_cast<char*>(&locationLen), sizeof(locationLen));
courseLocation.resize(locationLen);
in.read(&courseLocation[0], locationLen);

size_t instructorLen;
in.read(reinterpret_cast<char*>(&instructorLen), sizeof(instructorLen));
instructorName.resize(instructorLen);
in.read(&instructorName[0], instructorLen);

size_t timeSlotLen;
in.read(reinterpret_cast<char*>(&timeSlotLen), sizeof(timeSlotLen));
courseTimeSlot.resize(timeSlotLen);
in.read(&courseTimeSlot[0], timeSlotLen);
in.read(reinterpret_cast<char*>(&enrollmentCapacity),
sizeof(enrollmentCapacity));
in.read(reinterpret_cast<char*>(&enrolledStudentCount),
sizeof(enrolledStudentCount));

size_t locationLen;
in.read(reinterpret_cast<char*>(&locationLen), sizeof(locationLen));
courseLocation.resize(locationLen);
in.read(&courseLocation[0], locationLen);

size_t instructorLen;
in.read(reinterpret_cast<char*>(&instructorLen), sizeof(instructorLen));
instructorName.resize(instructorLen);
in.read(&instructorName[0], instructorLen);

size_t timeSlotLen;
in.read(reinterpret_cast<char*>(&timeSlotLen), sizeof(timeSlotLen));
courseTimeSlot.resize(timeSlotLen);
in.read(&courseTimeSlot[0], timeSlotLen);
}
Loading