473,626 Members | 3,947 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Needing some help on Classes and Constructors and proper definitions

2 New Member
This is what I have so far, I still need some help.

Student.h file:
Expand|Select|Wrap|Line Numbers
  1. #ifndef STUDENT_H
  2. #define STUDENT_H
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <cstdlib>
  7.  
  8. struct Name {
  9.   std::string firstName;
  10.   std::string lastName;
  11. };
  12.  
  13. enum Year {
  14.     FRESHMAN = 1,
  15.     SOPHMORE,
  16.     JUNIOR,
  17.     SENIOR,
  18. };
  19.  
  20. class Student
  21. {
  22. private:
  23.         Name name;
  24.         int idNumber;
  25.         std::string department;
  26.         Year year;
  27. public:
  28.         Student(const std::string& student, int id_number, const std::string& department, Years);
  29.         Student(const std::string& student, int id_number);
  30.         Student();
  31.  
  32.         int getidNumber();
  33.         std::string getName();
  34.         std::string getdepartment();
  35.         Year getYear();
  36.  
  37.         void setName(const Name& student_name);
  38.         void setidNumber(int id_number);
  39.         void setdepartment(const std::string student_department);
  40.         void setyear(Year students_current_year);
  41. };
  42.  
  43. #endif
Here is the error that Student.cpp is giving me:
Expand|Select|Wrap|Line Numbers
  1. Student.cpp:8:1: error: 'Student' does not name a type
  2.  Student::Student(const std::string& student, int id_number, const std::string& department, Year year)
  3.  ^~~~~~~
  4. Student.cpp:16:1: error: 'Student' does not name a type
  5.  Student::Student(const std::string& student, int id_number)
  6.  ^~~~~~~
  7.  
Student.cpp file:
Expand|Select|Wrap|Line Numbers
  1. #ifndef STUDENT_H
  2. #define STUDENT_H
  3.  
  4. #include <string>
  5. #include <cstdlib>
  6. #include "Student.h"
  7.  
  8. Student::Student(const std::string& student, int id_number, const std::string& department, Year year)
  9. {
  10.   Name name = setName();
  11.   idNumber = setidnumber();
  12.   department = setdepartment();
  13.   Year year = setyear();
  14. };
  15.  
  16. Student::Student(const std::string& student, int id_number)
  17. {
  18.   Name name = std::student;
  19.   idNumber = std::id_number;
  20. };
  21.  
  22. #endif
hw3.cpp file:
Expand|Select|Wrap|Line Numbers
  1. #ifndef STUDENT_H
  2. #define STUDENT_H
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <cstdlib>
  7. #include "Student.h"
  8. #include "Student.cpp"
  9.  
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14.   Student::student()
  15.  
  16.   void displayStudent(Student);
  17.  
  18.   return 0;
  19. }
  20.  
  21. #endif
Let me know where I'm making mistakes/lead/help me towards the right direction. Thanks so much!
Jul 6 '17 #1
3 1283
weaknessforcats
9,208 Recognized Expert Moderator Expert
This code in class Student won't compile and that would be enough for the compiler to say Student is not a type.

Expand|Select|Wrap|Line Numbers
  1. public:
  2.         Student(const std::string& student, int id_number, const std::string& department, Years);
  3.  

Look closely at the last argument of the constructor. All it says is Years. It needs a type. Like enum Year:

Try this:

Expand|Select|Wrap|Line Numbers
  1. public:
  2.         Student(const std::string& student, int id_number, const std::string& department, enum Year Years);
  3.  
  4.  
  5.  
  6.  
Post again if you are still stuck.
Jul 7 '17 #2
Semirxbih
2 New Member
It's still throwing off numerous errors even with enum defined.
Jul 7 '17 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
The number of errors is not important. Error 1 can cause Error 2,3,4,5,6, etc...

What you have to do is fix the first error only. Then recompile. If there are still errors, fix only the first one and recompile. You will eventually get them all.
Jul 7 '17 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1555
by: Martien van Wanrooij | last post by:
I am rather new at the classes concept in php so maybe I am overseeing something very simple but anyway I tried the following code: <?php class Navbar { var $begin = ""; function Navbar($bBegin = "") { $this->begin = $bBegin; $this->tussen = $bTussen;
2
7645
by: John Smith | last post by:
A friend's small business has gotten themselves in trouble. Their only programmer has recently skipped the country and did not leave the source code or any design notes for a couple of program modules. It appears that he did all the work for those few modules on his own laptop and never integrated them into Visual Source Safe. What tools, if any, exist in the VB world to disassemble / reverse engineer these modules?
2
1618
by: JDevine | last post by:
Hey. I posted a info about a program I have written that uses google to get and download files by type and site. I need HELP!!! This program is finished except for 2 features which, having tried for two weeks to create I cannot. This is my first program EVER. I simply an stuck. Please help. I was allowed by my employer to experiment with programing / open source. I'd like to be able to deliver a complete program, (so I can possibly...
46
5124
by: Kingdom | last post by:
In my data base I have a list of componet types e.g. type A - I have 8 off - type B I have 12 off etc. I'm using Set objRS = objDC.Execute("Select DISTINCT Component_Type FROM Parts_Table") to populate a drop down but would like to use several drop downs restricting the contents of each drop down to the records pertaining to one
5
1811
by: Tommy Lang | last post by:
Hi !! I am a c++ novice and I would appreciate any help with the following: I have created a class called "Number". In the main function of my program I call the class constructor twice like this(at start up)... int main(){ Number no1; Number no2; .......
2
1189
by: Stephen | last post by:
Im new to VB.net....Im having a problem understandign how a constructor relates to the base form and a class. What is the function on the constructor ..does it accept variables passed to it from the form? Steve
7
3744
by: try2nd | last post by:
I have console application where i can read line by line from a .txt file and save it to a different file name in .txt format as well. Here's the basic code: using System.IO namespace Dim fs As New FileStream(reportPath, FileMode.Open, FileAccess.Read) Dim fs1 As New FileStream(writePath, FileMode.Create, FileAccess.Write) Dim oReader As New StreamReader(fs) Dim oWrite As New StreamWriter(fs1) Dim sLine As String = ""
0
1213
by: Raffi B. | last post by:
I have a form named MainWindow in my project. Visual Studio C# Express automatically creates MainWindow.Designer.cs and MainWindow.resx as partial classes on MainWindow. I am trying to add a new C# class file named MainWindow.EventHandlers.cs to the project as a partial class of MainWindow using... partial class MainWindow { }
0
980
by: KeithAL | last post by:
I'm a student whose taking comp 110, and my professor gave the class a practice exam to help us study for our exam on tuesday. The question is: A perfect number is a positive integer that is equal to the sum of its proper divisors. A proper divisor is a positive integer other than the number itself that divides the number evenly (i.e., no remainder). For example, six is a perfect number because the sum of its proper divisors 1,2, and 3...
8
1063
by: irishwoman0980 | last post by:
i am using access 2010 and needing it to open a word.docx so that the user can just add an address to it and be done. i have already created the template word.docx just need help linking the two together with a command button. haven't done code in a very long time and cant remember how to.
0
8199
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8638
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8365
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5574
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.