I wanted to learn how to make a separate file for all the class in my code although I'm only using two so far but I wanted to remove it to another separate file where it's going to be my next step on making my code organized
but I keep getting some kind of error these lines and I have no idea why
or what does it mean
and really would appreciate it if someone would help me out here with it ^_^
first of all that is the main file nothing fancy
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
#include <string>
#include "people.h"
using namespace std;
#define n '\n'
void main()
{
int num;
cout<<"Hello and welcome to this thing that i'm learning ^_^"<<n<<"hope you would enjoy it as much as i'm :3"<<n;
cout<<"how many people information do you want to enter ?"<<n;
do
{
cout<<"Note that the number you are going to enter mustn't be bigger that 100 no matter what"<<n;
cin>>num;
}while(num>100);
people x;
cout<<"Name: "<<x.getName()<<n;
cout<<"SSN: "<<x.getSSN()<<n;
cout<<"Age: "<<x.getAge()<<n;
cout<<"Mobile: "<<x.getMobilephone()<<n;
cout<<"Home Phone: "<<x.getHomephone()<<n;
cout<<"Email: "<<x.getEmail()<<n;
cout<<"Collage: "<<x.get_collage_name()<<n;
cout<<"Over all Grade: "<<x.get_over_all_grade()<<n;
}
|
I have no error in this file
and this is
people.h file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#ifndef PEOPLE_H
#define PEOPLE_H
#pragma once
class people
{
public:
people();
void setName();
string getName();
void setAge();
int getAge();
void setSSN();
string getSSN();
void set_collage_name();
string get_collage_name();
void set_over_all_grade();
char get_over_all_grade();
void setEmail();
string getEmail();
void setHomephone();
string getHomephone();
void setMobilephone();
string getMobilephone();
private:
string name;
int age;
int long SSN;
string collage_name;
char over_all_grade;
string email;
string mobile_phone;
string home_phone;
};
#endif
|
I get error in this lines as listed below
line 30
line 32
line 17
line 21
line 23
line 25
line 11
line 15
line 34
line 33
line 27
line 34
and for the last file
people.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#include <iostream>
#include <string>
#include "people.h"
using namespace std;
#define n '\n'
void people::setName()
{
string x;
cout<<"Enter your name"<<n;
getline(cin,x);
name = x;
}
string people::getName()
{
return name;
}
void people::setAge()
{
int x;
cout<<"Enter your age"<<n;
cin>>x;
age = x;
}
int people::getAge()
{
return age;
}
void people::set_collage_name()
{
string x;
cout<<"Enter your collage name ?"<<n;
cin>>x;
collage_name = x;
}
string people::get_collage_name()
{
return collage_name;
}
void people::set_over_all_grade()
{
char x;
cout<<"Enter your over all grade ?"<<n;
cin>>x;
over_all_grade = x;
}
char people::get_over_all_grade()
{
return over_all_grade;
}
void people::setEmail()
{
string x;
cout<<"Enter your email ?"<<n;
cin>>x;
email = x;
}
string people::getEmail()
{
return email;
}
void people::setHomephone()
{
string x;
cout<<"Enter your home phone ?"<<n;
cin>>x;
home_phone = x;
}
string people::getHomephone()
{
return home_phone;
}
void people::setMobilephone()
{
string x;
cout<<"Enter your Mobile phone number"<<n;
cin>>x;
mobile_phone = x;
}
string people::getMobilephone()
{
return mobile_phone;
}
people::people()
{
setName();
setSSN();
setAge();
setMobilephone();
setEmail();
setHomephone();
set_collage_name();
set_over_all_grade();
}
|
I get error in this lines as listed below
line 36
line 40
line 58
line 62
line 69
line 73
line 80
line 84
line 14
line 18
line 39
line 61
line 72
line 83
line 17
I have no idea what so ever what I made wrong
and I'm still learning so I'm kind of new to all of this
so please forgive me if I made a really stupid mistake :3
Edit: I fixed all the things that made the code not working thanks to wildblue
and here is the code after fixing
the main.cpp has not changed
as for people.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#ifndef PEOPLE_H
#define PEOPLE_H
#include <string>
using namespace std;
#pragma once
class people
{
public:
people();
void setName();
string getName();
void setAge();
int getAge();
void setSSN();
int getSSN();
void set_collage_name();
string get_collage_name();
void set_over_all_grade();
char get_over_all_grade();
void setEmail();
string getEmail();
void setHomephone();
string getHomephone();
void setMobilephone();
string getMobilephone();
private:
string name;
int age;
int long SSN;
string collage_name;
char over_all_grade;
string email;
string mobile_phone;
string home_phone;
};
#endif
|
and for people.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
#include <iostream>
#include <string>
#include "people.h"
using namespace std;
#define n '\n'
void people::setName()
{
string x;
cout<<"Enter your name"<<n;
getline(cin,x);
name = x;
}
string people::getName()
{
return name;
}
void people::setAge()
{
int x;
cout<<"Enter your age"<<n;
cin>>x;
age = x;
}
int people::getAge()
{
return age;
}
void people::set_collage_name()
{
string x;
cout<<"Enter your collage name ?"<<n;
getline(cin,x);
collage_name = x;
}
string people::get_collage_name()
{
return collage_name;
}
void people::set_over_all_grade()
{
char x;
cout<<"Enter your over all grade ?"<<n;
cin>>x;
over_all_grade = x;
}
char people::get_over_all_grade()
{
return over_all_grade;
}
void people::setEmail()
{
string x;
cout<<"Enter your email ?"<<n;
cin>>x;
email = x;
}
string people::getEmail()
{
return email;
}
void people::setHomephone()
{
string x;
cout<<"Enter your home phone ?"<<n;
cin>>x;
home_phone = x;
}
string people::getHomephone()
{
return home_phone;
}
void people::setMobilephone()
{
string x;
cout<<"Enter your Mobile phone number"<<n;
cin>>x;
mobile_phone = x;
}
string people::getMobilephone()
{
return mobile_phone;
}
void people::setSSN()
{
int long x;
cout<<"Enter your SSN"<<endl;
cin>>x;
SSN = x;
}
int people::getSSN()
{
return SSN;
}
people::people()
{
setName();
setSSN();
setAge();
setMobilephone();
setEmail();
setHomephone();
set_collage_name();
set_over_all_grade();
}
|
now there is one problem that I still don't know how to fix
getline(cin,x);
in the collage name and the user name
it just escape it like there is no function to call
any idea why ???