So I have been self studying C++ and I've come across a concept that I don't entirely understand. It's mainly dealing with how the function parameter interacts with the main block.
#include <iostream>
#include <string>
using namespace std;
class GradeBook
{
public:
void displayMessage(string courseName)
{
cout << "Welcome to the gradebook for " << courseName <<endl;
}
};
int main()
{
string nameOfCourse;
GradeBook myGradeBook;
cout <<"Please enter the course name:" <<endl;
getline(cin, nameOfCourse);
myGradeBook.displayMessage(nameOfCourse);
You make a function with a string parameter with the name being coursename. You then look at the last line of code. 'myGradeBook.displayMessage(nameOfCourse); And the program knows that you're talking about the courseName variable. How is this possible since they are two different variables. I understand that you're using the mygradebook object to access the displaymessage but the parameter of nameOfCourse confuses me. How does it tie in with the gradebook function class? Thank you for the help should you look this over.