上海交通大学交大密西根 联合学院·一 ◆ 181 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Composition of a Program Preprocessor those being included will be inserted into your program before #include <vg101class.h> compilation <vg101class.h>for Vg101class.lib specially #include“MsgConsoleT.h” designed for this course using namespace std; <MsgConsoleT.h>is defined for this prog. /display welcome msg * ● using namespace std /necessary int main (void) Enclosed in /*..*are comments Main function:every console program will have one and only one main function Start of the function body Body of the main function )end of the function body
Composition of a Program Composition of a Program #include <vg101class.h> #include “MsgConsoleT.h” using namespace std; /* display welcome msg */ int main (void) { …. } • Preprocessor : those being included will be inserted into your program before compilation • <vg101class.h> for Vg101class.lib specially designed for this course • <MsgConsoleT.h> is defined for this prog. • using namespace std // necessary • Enclosed in /* … */ are comments • Main function: every console program will have one and only one main function • ‘{‘ Start of the function body • Body of the main function • ‘}’ end of the function body
上海交通大学交大密西根 联合学院·一 ◆ ■ 181 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Composition of a Function int main (void) main function declaration ‘'Function body start MsgConsoleT console; Variable declaration;here an object called console is declared to be of class MsgConsoleT console.printLine Method function printLine of ("welcome to the Vg101 class ConsoleT is called. class"); return 0; Return statement End of the function body
Composition of a Function Composition of a Function int main (void) { MsgConsoleT console; console.printLine ("welcome to the Vg101 class“); return 0; } • main function declaration • ‘{’ Function body start • Variable declaration; here an object called console is declared to be of class MsgConsoleT • Method function printLine () of class ConsoleT is called . • Return statement • ‘}’ End of the function body
上海交通大学交大密西根 联合学院 ■ UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University A few More Details To use the member date and function defined in another class,you could declare that class to be the base class of your class using syntax like class <your_class>:public <another_class> In your later homework,your might need to define a particular class for the task you are required to accomplish.For the purpose of automatic program grading,you will be given some function like disp (so that you can focuses on algorithm design instead of the output format
A few More Details A few More Details • To use the member date and function defined in another class, you could declare that class to be the base class of your class using syntax like class <your_class> : public <another_class> • In your later homework, your might need to define a particular class for the task you are required to accomplish. For the purpose of automatic program grading, you will be given some function like disp () so that you can focuses on algorithm design instead of the output format
上海交通大学交大密西根 联合学院· 81 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University About ConsoleT If your class will be run in a console environment (text based window),your class should have a base class called ConsoleT defined by the class. There are a few usefule functions defined in ConsoleT like printLine O and readInt O as you will see in the later examples.You can use it to print multiple items as the“cout”used in your textbook. There is a count part of the printLine called readLine,which is equivalent to“cin
About ConsoleT ConsoleT • If your class will be run in a console environment (text based window), your class should have a base class called ConsoleT defined by the class. • There are a few usefule functions defined in ConsoleT like printLine () and readInt () as you will see in the later examples. You can use it to print multiple items as the “cout” used in your textbook. • There is a count part of the printLine () called readLine (), which is equivalent to “cin
functions defined in ConsoleT int readInt (string msg); double readDouble (string msg); string readString (string msg); void runTimeError (string msg); void printLine(.…); void readLine (...) ● To use method functions defined in ConsoleT,you first define an object which is an instance of ConsoleT
functions defined in functions defined in ConsoleT ConsoleT int readInt (string msg); double readDouble (string msg); string readString (string msg); void runTimeError (string msg); void printLine (…); void readLine (…); • To use method functions defined in ConsoleT, you first define an object which is an instance of ConsoleT ConsoleT console ;