0

Very new to C++. Could use some help with this assignment on classes. The assignment requirement is:

Create a class called CourseList that includes one instance variables— nameOfCollege (type String). Provide a displayMessage member function to welcome the user to the CourseList program. Provide a set function that sets the name of the college, and a get function that retrieves the name of the college. The set function should have one string parameter for the name of the college. Use the function main() to demonstrate class Course’s capabilities.

To demonstrate our understanding of classes, we are to create classes, with objects, with functions. The end result is a console app to view fake classes offered at a fake college.

Currently, my get function is not returning the string with my fake college name. This is what I'm trying to resolve currently. I think my issue is with how I've written my functions or how my objects have been constructed.

Here is my code:

// DJ Homework 
// welcome function [done]
// set function w/ college name in parameter [maybe done?]
// get function [not done]
// return string [not done]
// display class list  [not done]


#include <iostream>
#include <string> // program uses C++ standard string class
using namespace std;

// CourseList class definition
class CourseList
{
private:
    // string here
    string nameOfCollege;

public:
    void setCollegeName(string nameOfCollege);
    string getCollegeName();

    void CourseList::mysetCollegeName(string nameOfCollege)
    {
        nameOfCollege = "Smart Peoples University";
    }

    string CourseList::mygetCollegeName()
    {
        return string();
    }     

    // function that displays a welcome message to the CourseList user 
    void displayMessage(string nameOfCollege) const
    {
        cout << "Welcome to the CourseList Program\n\n\n" << "To see the classes offered at " << nameOfCollege << ",type something, then press 'Enter'.";       
    } // end function displayMessage
}; // end class GradeBook  

// function main begins program execution
int main()
{
    string CollegeName; // string of characters to store the college         name
    CourseList myWelcome; // create a CourseList object named myWelcome

    myWelcome.displayMessage(CollegeName);
} // end main

So that's my homework and attempt at accomplishing said tasks. Any help with my assignment, or with C++ in general, would be greatly appreciated.

2
  • 1
    Look at what your mygetCollegeName method is returning. Is that the right variable? Commented Feb 2, 2016 at 4:27
  • Why do you have mysetCollegeName() as well as setCollegeName()? And instead of passing the college name into the displayMessage() function shouldn't that print out the member variable nameOfCollege? Commented Feb 2, 2016 at 4:34

2 Answers 2

2

It seem that you are very new to programming. There are several issues in your code and your method is ambiguous. Below is your code after modifications.

#include <iostream>
#include <string> // program uses C++ standard string class
using namespace std;

// CourseList class definition
class CourseList
{
private:
    // string here
    string nameOfCollege;
public:
    void mysetCollegeName()
    {
        nameOfCollege = "Smart Peoples University";
    }
    // function that displays a welcome message to the CourseList user 
    void displayMessage() const
    {
        cout << "Welcome to the CourseList Program\n\n\n"
            << "To see the classes offered at " << nameOfCollege << ", type something, then press 'Enter'.";
    } // end function displayMessage
}; // end class GradeBook  

// function main begins program execution
int main()
{
    string CollegeName; // string of characters to store the college         name
    CourseList myWelcome; // create a CourseList object named myWelcome
    myWelcome.mysetCollegeName();
    myWelcome.displayMessage();
} // end main

// * DJ Tonedeaf *  
Sign up to request clarification or add additional context in comments.

1 Comment

According to OP, the setCollegeName() should have a string parameter.
1

There are a number of issues in this code.

  1. You have two pairs of get and set functions with different names; keep one only
  2. Since you are defining your functions in the same class, you do not need CourseList:: before a function name
  3. Your get function is returning an empty string, which is of no use; return nameOfCollege; will make more sense here
  4. Inside your main() function, you are not initializing CollegeName so displayMessage() won't display any College Name

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.