What is Class.
A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions.
What is #include<iostream>
Stream-based I/O
The stream-based input/output library is organized around abstract input/output devices. These abstract devices allow the same code to handle input/output to files,
Why we use string header.
A variable of type string
represents a string of characters such as “ C++ Programming". A
string is actually an object of the C++ Standard Library class string. This class is defined
in header <string>, and the name string, like cout, belongs to namespace std
getline(); function
The getline() string function is used to input a string including whitespaces. There is also another string function get() to input string but this getline() function is much more efficient than get() function.
Syntax:
getline(name,maxsize)
The first argument indicates the name of the array which is used to store the string. The size of the array should be large enough that it can store the entire string. It is our responsibility to keep the size of array large enough to store the string. The second argument indicates the maximum size of array in which the string is to be stored. It will read the string until the size limit exists.
// Defining and Testing Class GradeBook
#include <iostream>
#include<conio.h>
#include<string>
using namespace std;
// GradeBook class definition
class Name
{
public:
// function that displays a welcome message to the GradeBook user
void displayMessage(string namecource )
{
cout << "Welcome to the grade book for\n" << namecource<< "!"<< endl;
} // end function displayMessage
}; // end class Name
// function main begins program execution
int main()
{
// string of characters to store the course name
string nameOfcorce;
Name shehry; // create a Name object named shehry
// prompt for and input course name
cout << "Please enter the course name:" << endl;
getline(cin,nameOfcorce); // read a course name with blanks
cout << endl; // output a blank line
// call shehry's displayMessage function
// and pass nameOfCourse as an argument
shehry.displayMessage(nameOfcorce);
getch();
return 0;
} // end main
A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions.
What is #include<iostream>
Stream-based I/O
The stream-based input/output library is organized around abstract input/output devices. These abstract devices allow the same code to handle input/output to files,
Why we use string header.
A variable of type string
represents a string of characters such as “ C++ Programming". A
string is actually an object of the C++ Standard Library class string. This class is defined
in header <string>, and the name string, like cout, belongs to namespace std
getline(); function
The getline() string function is used to input a string including whitespaces. There is also another string function get() to input string but this getline() function is much more efficient than get() function.
Syntax:
getline(name,maxsize)
The first argument indicates the name of the array which is used to store the string. The size of the array should be large enough that it can store the entire string. It is our responsibility to keep the size of array large enough to store the string. The second argument indicates the maximum size of array in which the string is to be stored. It will read the string until the size limit exists.
// Defining and Testing Class GradeBook
#include <iostream>
#include<conio.h>
#include<string>
using namespace std;
// GradeBook class definition
class Name
{
public:
// function that displays a welcome message to the GradeBook user
void displayMessage(string namecource )
{
cout << "Welcome to the grade book for\n" << namecource<< "!"<< endl;
} // end function displayMessage
}; // end class Name
// function main begins program execution
int main()
{
// string of characters to store the course name
string nameOfcorce;
Name shehry; // create a Name object named shehry
// prompt for and input course name
cout << "Please enter the course name:" << endl;
getline(cin,nameOfcorce); // read a course name with blanks
cout << endl; // output a blank line
// call shehry's displayMessage function
// and pass nameOfCourse as an argument
shehry.displayMessage(nameOfcorce);
getch();
return 0;
} // end main