-
July 6th, 2017, 07:01 AM
#1
Classes and Constructors
Looking at getting some basic help on proper construction of this project.. Here is the assignment:
Code:
Student.h
– In this file, you declare a class named Student.
– This class contains 4 private attributes, name, idNumber, department, and year.
– name is a struct that contains two strings: firstName and lastName.
– idNumber is an integer and department is a string.
– year is an enum that contains four possible values: FRESHMAN, SOPHOMORE, JUNIOR, SENIOR.
– Note that struct and enum declarations should be placed before the class declaration.
– Define public getter functions and setter functions for all 4 attributes, that is, 4 getters and 4 setters.
• Student.cpp
– In this file, you provide definitions for 3 constructors of Student.
– The first constructor takes 4 parameters, one for each attribute, then initializes the attributes accordingly.
– The second constructor takes 2 parameters, one for name and one for idNumber, then initializes those
attributes accordingly. The remaining 2 attributes are initialized as “” (empty string) and FRESHMAN,
respectively.
– The third constructor is a default constructor that takes no parameters. Here, the 4 attributes are initialized
as “” (firstName), “” (lastName), 0 (idNumber), “” (department) and FRESHMAN (year), respectively.
• hw3.cpp
– In this file, you define main function.
– In the main function, first create at least 3 Student objects.
– The first object must be created using the first constructor (4 parameters).
– The second object must be created using the second constructor (2 parameters).
– Since the second constructor does not provide proper information for department and year, set those
values by calling their associated setter functions.
1
– The third object must be created using the default constructor.
– Since the default constructor does not provide proper information for any attributes, set all 4 values by
calling their associated 4 setter functions.
– After creating all the objects, call a function named displayStudent for each student to print all the
information (all 4 attributes) about the student. Note that this function must be called at least 3 times to
print all objects. The displayStudent function must have the following prototype:
void displayStudent(Student);
– When displaying year, make sure the freshman year starts at 1, not 0.
Example run:
Name: Roger Federer
ID Number: 12345
Department: Art
Year: 4
Name: Rafael Nadal
ID Number: 56789
Department: Computer Science
Year: 3
Name: Novak Djokovic
ID Number: 13579
Department: Physics
Year: 1
Here is what I have so far, and I can't seem to understand the rest.
Here is my Student.h file:
Code:
#ifndef STUDENT_H_EXISTS
#define STUDENT_H_EXISTS
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
struct name {
string firstName, lastName;
};
class Student {
private:
struct name;
int idNumber;
string department;
int year;
public:
Student();
int getidNumber();
string getName();
string getdepartment();
enum getyear {
FRESHMAN = 1,
SOPHMORE = 2,
JUNIOR = 3,
SENIOR = 4
};
void setName() const;
void setidNumber() const;
void setdepartment() const;
void setyear() const;
};
#endif
Let me know if I'm on the right track or give me any help/tips I can use, this is a beginner C++ class so nothing fancy.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|