1

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;
}
4
  • 3
    The first declaration in main is a function declaration. Move on from there. Commented May 22, 2015 at 17:57
  • SO is not for building your program for you. This is a template if anything. Show some progress and then I will help Commented May 22, 2015 at 17:59
  • 1
    You don't need to include both .cpp and .h. You should only be including .h Commented May 22, 2015 at 18:03
  • 1
    Students Students(); ... Really? You also once refer to _Students :( Commented May 22, 2015 at 19:31

1 Answer 1

0

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"
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.