Instance 1
Topic: Define a Dog class that contains attributes such as Age,weight, as well as methods for manipulating these properties. Implement and Test this class.
Description: This is my textbook after the class, mainly for the practice of class, the content is written by themselves, you casually write on the line.
SOURCE program:
Program execution Results
After pressing any key
3 seconds later
Example 2:
Topic: Define a Circle class, have the data member radius (RADIUS), member function Getarea (), compute the area of the circle, construct a circle object to test
Analysis: Textbook After class, I wrote a very simple small program
Program execution Results
Instance 3
Writing a program is familiar to the scope. The global variables declared in this example have namespace scopes that are valid throughout the file.
Knowledge points: Mainly to test the scope of the wipe.
SOURCE program:
Execution results:
Instance 4
Write programs to learn about the lifetime and visibility of variables.
Knowledge Point: The lifetime of an object can be divided into static lifetime and dynamic lifetime. The rest of the objects have dynamic lifetimes in addition to the objects declared in the namespace scope and those that are decorated with the keyword static in the local scope.
SOURCE program:
Program execution Results:
Instance 5
A clock program with static and dynamic lifetime objects.
Knowledge Point: Here still takes the clock class as an example, in this instance, declared has the function prototype scope, the local scope, the class scope and the namespace scope multiple objects
Program execution Results:
Analysis: In this program, variables and objects with various scope types are included. The 3 parameters of the function member SetTime in the Clock class definition have the function prototype scope, the SetTime function definition 3 parameter, the object Myclock has the local scope, the clock class data, the function member has the class scope, the object Globclock has the namespace scope. In the main function, these variables, objects, and the public members of the object are visible. In terms of lifetime, except for objects with a namespace scope, Globclock has a static lifetime, and the rest has a dynamic lifetime, as in the case of the program's runtime.