Reputation: 13
Hello everyone im trying to build a program that ask for user to input multiple names but i want to create one function to do it all that way i dont have to do cout enter first name, cout enter second name. In the process of writting this program i got stuck and my class is not being recognized and or running any help is greatly appreciated.
//StudentMain.cpp
#include <iostream>
#include <iomanip>
#include "Students.h"
#include "Students.cpp"
using namespace std;
int main()
{
Students Students();//("sue", "Jones", "3.2");
cout << "Employee Info obtained by get functions: \n"
<< "\nFirst name is: " << _Students.getFirstName()
<< "\nLast Name is: " << Students.getLastName()
<< "\nGPA is: " << Students.GPA() << endl;
cout << "\n updated information\n" << endl;
Students.print();
return 0;
}
//Students.h
#ifndef COMMISSION_H
#define COMMISION_H
#include <string>
class Students
{
public:
Students(const std::string &, const std::string &, float = 0.0);
void setFirstName(const std::string &);
std::string getFirstName() const;
void setLastName(const std::string &);
std::string getLastName() const;
void setGPA(float);
float getGPA() const;
void print() const;
//std::string firstName;
//std::string lastName;
//float gpa;
private:
std::string firstName;
std::string lastName;
float gpa;
};
#endif
//Students.cpp
#include <iostream>
#include <stdexcept>
#include "Students.h"
#include <cmath>
using namespace std;
Students::Students(const string &first, const string &last, float gpa)
{
firstName = first;
lastName = last;
setGPA(gpa);
}
void Students::setFirstName(const string & first)
{
firstName = first;
}
string Students::getFirstName() const
{
return firstName;
}
void Students::setLastName(const string &last)
{
lastName = last;
}
string Students::getLastName() const
{
return lastName;
}
void Students::setGPA(float gpa)
{
if (gpa < 4.1)
throw invalid_argument("GPA must be set below 4.0");
}
float Students::getGPA() const
{
return gpa;
}
void Students::print() const
{
cout << "Students Information:\t " << firstName << ' ' << lastName
<< "\n GPA:" << gpa;
}
Upvotes: 1
Views: 97
Reputation: 293
Instead of declaring a variable of type Students
you're declaring a function Students()
of return type Students
. Small mistake, so easy fix:
...
int main()
{
Students student;//("sue", "Jones", "3.2");
cout << "Employee Info obtained by get functions: \n"
...
Upvotes: 0