I have 6 files .h and .cpp. can i share them w/ u and u can check
Assistant
I'd love to help, but I'm currently unable to directly access, view, or process attachments or external files. However, I can still provide assistance! If you have specific questions, errors, or need guidance on certain aspects of your C++ code, you can paste small, specific parts of your code here, and I can give advice, explanations, or help troubleshoot issues based on that.
Remember to keep it focused and concise to get the best possible assistance!
User
Assistant
Degree.h
#pragma once
#include
enum class DegreeProgram {SECURITY, NETWORK, SOFTWARE };
static const std::string DegreeProgramStr[] = {"SECURITY", "NETWORK", "SOFTWARE"};
Student.h
#pragma once
#include
#include
#include "Degree.h"
class Student {
public:
const static int daysToCompleteCourses = 3; // Array holding number of days to complete each course
private:
std::string studentID;
std::string firstName;
std::string lastName;
std::string emailAddress;
int age;
int numberOfDays[daysToCompleteCourses];
DegreeProgram degreeProgram;
public:
Student();
// Constructor
Student(std::string studentID, std::string firstName, std::string lastName, std::string emailAddress, int age, int numberOfDays, DegreeProgram degreeProgram);
// Destructor
~Student();
// Accessor functions for each instance variable
std::string getStudentID();
std::string getFirstName();
std::string getLastName();
std::string getEmailAddress();
int getAge();
int* getNumberOfDays();
DegreeProgram getDegreeProgram();
code
// Mutator functions for each instance variable
void setStudentID( std::string studentID);
void setFirstName( std::string firstName);
void setLastName( std::string lastName);
void setEmailAddress( std::string emailAddress);
void setAge(int age);
void setNumberOfDays(int numberOfDays[]);
void setDegreeProgram(DegreeProgram dp);
// print() to print specific student data
void print();
Your code snippet for the Student class and its methods in C++ looks mostly fine with the intent on handling student data, including their degree program. However, there are a few errors and potential improvements that could be addressed:
Mutator for studentID, firstName, lastName, emailAddress, age, and degreeProgram parameters: There's a mismatch between parameter names in the declaration and usage inside the methods, causing potential issues (e.g., the parameters should be consistent, following camelCase or another naming convention uniformly).
In your setStudentID, setFirstName, setLastName, setEmailAddress, setAge, and setDegreeProgram methods, you're not using the parameter names consistently. For example, in setStudentID, you should use setStudentID(std::string studentID) and then assign it correctly within the method. This issue also appears in other setter methods you've written.
Errors in Mutator implementations:
void Student::setDegreeProgram(DegreeProgram dp) { this->degreeProgram dp; } is syntactically incorrect. It should be:
In setNumberOfDays, you've written void Student::setnumberOfDays(numberOfDays[]). It lacks the data type for the array, and you should declare the function like void Student::setNumberOfDays(int numberOfDays[]).
Accessing Arrays:
In the print function, you incorrectly call this->numberOfDays() as if it were a function. It should be this->numberOfDays directly since it's an array, not a function call.
Initialization List for Constructors:
It's a good practice to use an initialization list in your constructor where applicable. It can make the code cleaner, especially for the array and enum initialization.
Typos in Destructor Comment:
You've written "Distructor does nothing" in the comment above the destructor definition. It's a minor typo - it should be "Destructor does nothing".
Include Guard in .cpp File:
#pragma once is not typically used or necessary in .cpp files. It's meant for header files to prevent multiple inclusions. You can remove it from Student.cpp.
Here's a quick revision example for one of the setters:
Every parameter within setters and getters must match the actual member variables to work correctly.
Please adjust these issues accordingly, and your class should work more effectively. If you have any further questions or need additional clarifications on another part of your code, feel free to ask!