Lesson 19: VIP | Self-Learning C++ with Kids

Lesson 19: VIP | Self-Learning C++ with Kids

Program 1:

Ticket Check

(Regular·Business)

【Code 29 lines】Output as shown in the figure

#include <iostream>

using namespace std;

int main(){

int isOK;

string speedboat;

while(true){

cout<<“If you have a ticket, please enter 1″<<endl;

cin>>isOK;

if(isOK!=1){

cout<<“Please purchase a ticket first”<<endl;

}

else if(isOK=1){

cout<<“Please enter!”<<endl;

cout<<“Please enter the type of ticket (Regular, Business)”<<endl;

cin>>speedboat;

if(speedboat==”Regular”){

cout<<“Please go left to take the regular speedboat”<<endl;

}

else if(speedboat==”Business”){

cout<<“Please go right to take the business speedboat”<<endl;

}

else{

cout<<“Please enter according to the requirements”<<endl;

}

}

}

return 0;

}

Lesson 19: VIP | Self-Learning C++ with Kids

Program 2:

Login

(Account·Password)

【Code 27 lines】Output as shown in the figure

#include <iostream>

#include <string>

using namespace std;

int main(){

string username=”guyi”;

string password=”20250821″;

string Username,Password;

while(true){

cout<<“Please enter username”<<endl;

cin>>Username;

if(Username==username){

cout<<“Please enter password”<<endl;

cin>>Password;

if(Password==password){

cout<<“The magical door has opened! Welcome “<<username<<” to the magic forest”<<endl;

}

else{

cout<<“Incorrect password, please try again”<<endl;

}

}

else{

cout<<“Username does not exist, please try again”<<endl;

}

}

return 0;

}

Lesson 19: VIP | Self-Learning C++ with Kids

Program 3:

Odd and Even

(Positive·Negative)

【Code 20 lines】Output as shown in the figure

#include <iostream>

using namespace std;

int main(){

int x;

while(true){

cout<<“Please enter an integer”<<endl;

cin>>x;

if(x>0){

cout<<“This is a positive number”<<endl;

if(x%2==1){

cout<<“This is an odd number”<<endl;

}

else if(x%2==0){

cout<<“This is an even number”<<endl;

}

}

if(x==0){

cout<<“This is zero”<<endl;

}

if(x<0){

cout<<“This is a negative number”<<endl;

}

}

return 0;

}

Lesson 19: VIP | Self-Learning C++ with Kids

Review:

Lessons 15-18

【Lesson 15: Fever Triage】

if statement: If… then…;

English word: temperature, body temperature!

【Lesson 16: Multiple if Combinations】

Armstrong number: A three-digit number where the sum of the cubes of its digits equals the number itself. This “definition” has foundational research value in mathematics and computer science!

Lightning number: Also known as “Kaprekar number”, a special natural number whose square can be split into two parts that add up to the original number. For example, 55²=3025, 30+25=55!

Perfect number: A natural number that is equal to the sum of its proper divisors (excluding itself), such as 6, 28, 496, etc.; as of 2025, 51 “perfect numbers” have been discovered, all of which are even and closely related to “Mersenne” primes!

【Lesson 17: else, Constants】 Retail and Wholesale

Key point: Let else handle what if does not!

else: others;true: true;false: false!

Error: error; read-only: read-only; variable: variable!

const declares data types, “constant” names are defaulted to all uppercase!

Variables are changeable quantities; constants are unchangeable quantities.

If the value of a constant is “modified” in the program, then the program will error!

Constants are very useful in programming! (They improve code readability and maintainability while ensuring that “specific values” are not accidentally modified.)

【Lesson 18: Blood Pressure】 And, Or, Not!

Normal blood pressure: Systolic 90-139, Diastolic 60-89;

(Invalid data: “Systolic, Diastolic” not within limit range!)

Low blood pressure: Systolic <90, and Diastolic <60;

High blood pressure: Systolic ≥140, and Diastolic ≥90.

(Note: This judgment standard is hypothetical, please do not take it literally!)

Supplement:

Communicating with kids

【Self-Learning Notes】

Lesson 19: VIP | Self-Learning C++ with Kids

【Parent Comments】

Program two: Similar to the previous “Interest Programming”!

Program three: “Negative numbers” did not distinguish between “odd and even”!

Reason: Four to five, will only learn in the new semester!

AI response: Negative numbers also exist as odd and even!

(Already arranged: Will attempt to modify the program in the next issue!)

【Lesson 19: VIP】 Identification Channel!

No ticket, purchase a ticket first; With a ticket, Business VIP takes the fast track.

Leave a Comment