C++ (Class and void function)
ForewordYeah!! my dear friends, we also meet in this passage. I know C++ is hard for the Beginner, I feel the C++ is so hard, but I believe in C++ is benifit on the Big Data Calculation, it could make calculation performance efficiently. So C++ is significant for Big Data, I think you and me both Data Crazy Fans. We must insist to study more knowledge that we could help us do Data Project.
Text
#include<iostream>
#include<string>
using namespace std;
class GradeBook{
public:
void displayMessage(){
cout << "Welcome to the Grade Book!" << endl;
}
};
class Book{
public:
void displayinfo(string courseName){
cout << "Welcome to the book for\n" << courseName << "!" << endl;
}
};
int main(){
GradeBook myGradeBook;
myGradeBook.displayMessage();
string nameOfcourse;
Book BK;
cout << "Please enter the course name:" << endl;
getline(cin,nameOfcourse);
cout << endl;
BK.displayinfo(nameOfcourse);
}
From the above program, we know the class GradeBook have one void function displayMessage(), it hasn’t parameter, we couldn’t illustrate the function needn’t parameter. Void() function only illustrate the function needn’t return value. Defined String need advance load the head file, use Class need instantiating an Object, The Object could call function in the class, getline() function need load using namespace std to use it.It has parameters, cin is gain the user input string on screen, then it will assign the value to second parameter. endl to over the line content. BK.displayinfo(nameOfcourse); nameOfcourse is assigned value, the function displayinfo(string courseName), courseName is formal parameter, the nameOfcourse is actual parameter, it could pass to the function, and the function will use it.【function don’t use formal parameter】
In the end
I gratitude for your watch my article, I hope you could point my mistakes on my passages. I learn the C++ Programming is feel hard. I think it also hard for you【if you are a Beginner like me{ I am fool actually, I always learn something is slowly}】. Though it isn’t easy, we believe in our action is valuable, maybe it could make us happy!!【Hahaha】, it’s a challenge for us, it also is a wonder travel. I want you will like C++. Anything, please you never give up, insist to do it at last then you could become a winner in this Game. Cheers!! my dear friends, your Pan【one of common persons】
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]