RECOMMENDATION. Don't Write Entire Programs Unless You Want To Spend 3-10 Times As Long Doing Labs! Write 1 Function - Test That Function!
|
|
- Albert Woods
- 5 years ago
- Views:
Transcription
1 1
2 RECOMMENDATION Don't Write Entire Programs Unless You Want To Spend 3-10 Times As Long Doing Labs! Write 1 Function - Test That Function! 2
3 3
4 Copy Project Folder There will be a number of times when you submit Projects in Phases. If so, you will be ask to submit the labs separately. At this point you should have a working TomH-Student-1 project folder that demonstrates all that was illustrated in the slides of OOP-02-Classes-Slides-A.pptx [1] Place a copy of this lab the "To Be Graded Folder" of your Network Drop Box [2] Make a copy of this folder. Name the folder TomH-Student-2 Using your First Name & Last Name Initial If The Lab Is Broken Up Into Phases, You Are To Include Both Folders In Your Drop Box As Requested I Will Be Grading Them Separately! 4
5 5
6 # define STUDENT_DIAGNOSTIC_LEVEL 2 int main (int argc, char * argv[]) { puts (" "); puts (" "); puts ("++ Class Student Added To Main - Phase 2 ++"); puts ("++ ++"); puts ("++ Writen By ++"); puts ("++ Dr. Tom Hicks YOUR NAME ++"); puts (" "); puts (" \n"); puts (" Start Of Main \n"); TestStudent(); Make The Following Changes To main COMPILE THE PROGRAM! } puts (" HitCarriageReturnToContinue(); return (0); End Of Main \n"); Change the Diagnostic Level & the Phase 6
7 Diagnostic Level = 2 Note that the old testing no longer appears # define STUDENT_DIAGNOSTIC_LEVEL 2 COMPILE THE PROGRAM! 7
8 Make The Following Changes To main Diagnostic Level 1 was supposed to Create the Constructor and Destructor and to make sure that they compiled and fired accordingly. Once we have successfully completed this task, we do not want to see this output over and over again; but we would like to be able to revisit the testing code if we change/modify this class later during the maintenance life cycle. 8
9 9
10 Add This Starting Pragma Block Code Before The Student Documentation # pragma region STUDENT_DIAGNOSTIC_LEVEL_1 Constructor_Destructor //======== ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Student // // // // Purpose : Constructors for Class Student. Set Name to NewName and No to // // NewNo and Gender to NewGender. Default NewName = blank. // // Default NewNo = 0. Default Sex = FEMALE = false. // // // // Written By : Dr. Tom Hicks Environment : Windows 10 // // Date...: xx/xx/xxxx Compiler...: Visual Studio 2017 C++ // ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// Student::Student(char NewName[], long NewNo, bool NewGender) 10
11 Add This Ending Pragma Block Code Immediately After The Destructor Student::~Student(void) { # ifdef STUDENT_DIAGNOSTIC_LEVEL // if (STUDENT_DIAGNOSTIC_LEVEL <= 1) puts("evoking Destructor ~Student(void)"); # endif // STUDENT_DIAGNOSTIC_LEVEL } # pragma endregion I Often Use Pragma Sets To Organize My Functions! Programs & Files Can Get Long - The Pragma Sets Will Help Me Expose Those Functions That I Am Coding & Testing I Will Hide Those That I Think Are Tested & Working OK 11
12 # pragma region STUDENT_DIAGNOSTIC_LEVEL_1 Constructor_Destructor //=========== ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Student // // // // Purpose : Constructors for Class Student. Set Name to NewName and No to // // NewNo and Gender to NewGender. Default NewName = blank. // // Default NewNo = 0. Default Sex = FEMALE = false. // // // // Written By : Dr. Tom Hicks Environment : Windows 10 // // Date...: xx/xx/xxxx Compiler...: Visual Studio 2017 C++ // ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// Student::Student(char NewName[], long NewNo, bool NewGender) { # ifdef STUDENT_DIAGNOSTIC_LEVEL // if (STUDENT_DIAGNOSTIC_LEVEL <= 1) puts("evoking Constructor Student (NewName[], NewNo, NewGender)"); # endif // STUDENT_DIAGNOSTIC_LEVEL } strcpy_s(name, NewName); No = NewNo; Gender = NewGender; Student::Student(long NewNo, char NewName[], bool NewGender) { # ifdef STUDENT_DIAGNOSTIC_LEVEL // if (STUDENT_DIAGNOSTIC_LEVEL <= 1) puts("evoking Constructor Student (NewNo, NewName[], NewGender)"); # endif // STUDENT_DIAGNOSTIC_LEVEL Using the mouse, click on the - sign beside the starting pragma See How All Of This Code Can Be (+)Opened & (-) Closed As A Group } strcpy_s(name, NewName); No = NewNo; Gender = NewGender; ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // ~Student // // // // Purpose : Do all that is necessary to destroy an object. In this class we // // are only going to insert a diagnostic display to verify the the // // destructor is firing properly. // // // // Written By : Dr. Tom Hicks Environment : Windows 10 // // Date...: xx/xx/xxxx Compiler...: Visual Studio 2017 C++ // ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// Student::~Student(void) { # ifdef STUDENT_DIAGNOSTIC_LEVEL // if (STUDENT_DIAGNOSTIC_LEVEL <= 1) puts("evoking Destructor ~Student(void)"); # endif // STUDENT_DIAGNOSTIC_LEVEL } # pragma endregion
13 Add These Same Pragma Around The Test Function In TestStudent # pragma region STUDENT_DIAGNOSTIC_LEVEL_1 Constructor_Destructor //======== if (STUDENT_DIAGNOSTIC_LEVEL <= 1) { puts("\n\n"); puts("==================================================================="); puts("==================================================================="); puts("=========== Testing Constructor & Destructor =============="); puts("=========== STUDENT_DIAGNOSTIC_LEVEL = 1 =============="); puts("==================================================================="); puts("===================================================================\n"); Student Student1, Student2("Pete", 2222, MALE), Student3("Sandra", 3333), Student4("Amber"), Student5(5555, "Nathan", MALE), Student6(6666, "Betty"), Student7(7777), Class[4]; HitCarriageReturnToContinue(); } # pragma endregion This Will Allow Us To Hide The Test Code For Diagnostic Test Level 1 So That We Can Work On Diagnostic Test Level 2 13
14 14
15 Add A Prototype For Display // Classes & Structs class Student { public: Student(char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Student(long NewNo, char NewName[] = "", bool NewGender = MALE); ~Student(void); void Display(char Message[] = ""); private: char Name[20]; long No; bool Gender; }; Message Will Be An Optional Argument - Display Is Overloaded 15
16 Add The Documentation & Display Method maybe below destructor? # pragma region STUDENT_DIAGNOSTIC_LEVEL_2 Display //========================== ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Display // // // // Purpose : If there is a message, display it --> Return. // // Then display each of the private data members, one to a line. The // // output should look like: // // // // Optional Message... // // Name...: Tom Hicks // // No...: 1207 // // Gender.: Male // // ---- Skip a line // // // // Written By : Dr. Tom Hicks Environment : Windows 10 // // Date...: xx/xx/xxxx Compiler...: Visual Studio 2017 C++ // ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// void Student::Display(char Message[]) { } # pragma endregion Without Looking Ahead, Write The Code For This Method/Function 16
17 Add The Display Method maybe below destructor? # pragma region STUDENT_DIAGNOSTIC_LEVEL_2 Display //====================== void Student::Display(char Message[]) { if (strlen(message) > 0) puts(message); printf ("Name...: %-s\n", Name); printf ("No...: %ld\n", No); if (Gender == FEMALE) puts("gender.: Female\n\n"); else puts("gender.: Male \n\n"); } # pragma endregion If There Is No Optional Message, Print Nothing! 17
18 18
19 Let Us Start By Making A Copy Of The Test Code For Diagnostic Level 1 Make These Changes # pragma region STUDENT_DIAGNOSTIC_LEVEL_2 Display //======================= if (STUDENT_DIAGNOSTIC_LEVEL <= 2) { puts("\n\n"); puts("==================================================================="); puts("==================================================================="); puts("=========== Testing Display =============="); puts("=========== STUDENT_DIAGNOSTIC_LEVEL = 2 =============="); puts("==================================================================="); puts("===================================================================\n"); Student Student1, Student2("Pete", 2222, MALE), Student3("Sandra", 3333), Student4("Amber"), Student5(5555, "Nathan", MALE), Student6(6666, "Betty"), Student7(7777), Class[4]; Diagnostic Level 1 Tested All 8 Of The Ways To Test Our Two Constructors The Constructor Is Overloaded! } HitCarriageReturnToContinue(); 19
20 Let Us Start By Making A Copy Of The Test Code For Diagnostic Level 1 Make These Changes # pragma region STUDENT_DIAGNOSTIC_LEVEL_2 Display //======================= if (STUDENT_DIAGNOSTIC_LEVEL <= 2) { puts("\n\n"); puts("==================================================================="); puts("==================================================================="); puts("=========== Testing Display =============="); puts("=========== STUDENT_DIAGNOSTIC_LEVEL = 2 =============="); puts("==================================================================="); puts("===================================================================\n"); Student Student1, Student2("Pete", 2222, MALE), Student3("Sandra", 3333), Student4("Amber"), Student5(5555, "Nathan", MALE), Student6(6666, "Betty"), Student7(7777), Class[4]; Student1.Display ("This Is Student1"); Student2.Display (); Student3.Display ("This Is Student3"); Student4.Display ("This Is Student4"); Student5.Display ("This Is Student5"); Student6.Display ("This Is Student6"); Student7.Display ("This Is Student7"); for (int ClassNo = 0; ClassNo <= 3; ClassNo ++) Class[ClassNo].Display(); Diagnostic Level 2 Is Going To Verify That All 8 Of The Possible Constructors Were Successful! The Display Is Overloaded! } HitCarriageReturnToContinue(); 20
21 Examine Output Carefully To Make Sure It Works Don t Assume 1 Code That Generated Output Student1.Display ("This Is Student1"); How The Object Was Created Student Student1, Look At The Constructor Definition *Student(char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Student(long NewNo, char NewName[] = "", bool NewGender = MALE); In the beginning of the class, I am going to provide you lots of test code. At the end, you will do your own. Several Folks, last semester, received B's & C's on their labs because they did not bother to examine the output correctly & make obvious corrections. 21
22 Examine Output Carefully To Make Sure It Works Don t Assume 2 Code That Generated Output Student2.Display ( ); Tested Passing Nothing! How The Object Was Created Student Student2("Pete", 2222, MALE), Look At The Constructor Definition *Student(char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Student(long NewNo, char NewName[] = "", bool NewGender = MALE); CHECK THEM ALL OUT CAREFULLY! We Want To Test Our Classes Carefully! Add Them To Our Library! Reuse Them Like Crazy!
23 Examine Output Carefully To Make Sure It Works Don t Assume 3 Code That Generated Output for (int ClassNo = 0; ClassNo <= 3; ClassNo++) Class[ClassNo].Display(); How The Object Was Created Student Class[4]; Look At The Constructor Definition *Student(char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Student(long NewNo, char NewName[] = "", bool NewGender = MALE); It Works For Arrays!
24 Now That I Am Confident That The Display Works I Can Collapse The Display Function And Prepare To Do Diagnostic Level 3 Function Set I Can Also Collapse The Testing Code For Diagnostic Level 2 24
25 25
26 # define STUDENT_DIAGNOSTIC_LEVEL 3 int main (int argc, char * argv[]) { puts (" "); puts (" "); puts ("++ Class Student Added To Main - Phase 2 ++"); puts ("++ ++"); puts ("++ Writen By ++"); puts ("++ Dr. Tom Hicks YOUR NAME ++"); puts (" "); puts (" \n"); puts (" Start Of Main \n"); TestStudent(); Make The Following Changes To main COMPILE THE PROGRAM! } puts (" HitCarriageReturnToContinue(); return (0); End Of Main \n"); Change the Diagnostic Level 26
27 27
28 Add A Prototype For Set // Classes & Structs class Student { public: Student(char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Student(long NewNo, char NewName[] = "", bool NewGender = MALE); ~Student(void); void Display(char Message[] = ""); void Set (char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); private: char Name[20]; long No; bool Gender; }; There Are 3 Optional Arguments - Method Set Is Overloaded! 28
29 Add The Documentation & Set Method maybe below Display? # pragma region STUDENT_DIAGNOSTIC_LEVEL_3 Set//=============================== ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Set // // // // Purpose : Assign the following: // // // // Name = NewName // // No = NewNo // // Gender = NewGender // // // // Written By : Dr. Tom Hicks Environment : Windows 10 // // Date...: xx/xx/xxxx Compiler...: Visual Studio 2017 C++ // ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// void Student:: Set (char NewName[], long int NewNo, bool NewGender) { } # pragma endregion Remember: No Default Arguments In Function/Method Itself Without Looking Ahead, Write The Code For This Method/Function 29
30 Add The Set Method maybe below Display? # pragma region STUDENT_DIAGNOSTIC_LEVEL_3 Set//============================= void Student:: Set (char NewName[], long int NewNo, bool NewGender) { strcpy_s(name, NewName); No = NewNo; Gender = NewGender; } # pragma endregion We Need To Test It 30
31 31
32 Let Us Start By Making A Copy Of The Test Code For Diagnostic Level 1 Make These Changes # pragma region STUDENT_DIAGNOSTIC_LEVEL_3 Set//=========================== if (STUDENT_DIAGNOSTIC_LEVEL <= 3) { puts("\n\n"); puts("==================================================================="); puts("==================================================================="); puts("=========== Testing Set =============="); puts("=========== STUDENT_DIAGNOSTIC_LEVEL = 3 =============="); puts("==================================================================="); puts("===================================================================\n"); Student Student1, Student2("Pete", 2222, MALE), Class[4]; HitCarriageReturnToContinue(); } # pragma endregion Set Is Overloaded We Need Test Code To Test All Of The Possibilities 32
33 Let Us Start By Making A Copy Of The Test Code For Diagnostic Level 1 Make These Changes Student Student1, Student2("Pete", 1234, MALE), Class[4]; Student1.Set("Alpha", 111, FEMALE); Student1.Display("Student1 Set With Alpha, 111, FEMALE"); Class[0].Set("Beta", 222); Class[0].Display("Class[0] Set With Beta, 222"); Class[1].Set("Gamma"); Class[1].Display("Class[1] Set With Gamma"); Student1.Set(); Student1.Display("Student1"); HitCarriageReturnToContinue(); } # pragma endregion 33
34 Examine Output Carefully To Make Sure It Works Don t Assume Student Student1, Student2("Pete", 2222, MALE), Class[4]; Student1.Set("Alpha", 111, FEMALE); Class[0].Set("Beta", 222); Class[1].Set("Gamma"); Student1.Set(); 34
35 35
36 Accessors Accessor - A method that examines, but not change the state of an object. // Classes & Structs class Student { public: Student(char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Student(long NewNo, char NewName[] = "", bool NewGender = MALE); ~Student(void); }; void Display(char Message[] = ""); void Set (char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Display Is An Accessor 36 36
37 Mutators Mutator- A method that changes the state of an object. // Classes & Structs class Student { public: Student(char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Student(long NewNo, char NewName[] = "", bool NewGender = MALE); ~Student(void); void Display(char Message[] = ""); }; void Set (char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Set Is An Mutator 37 37
38 38
39 Overloaded Functions/Methods Overloaded Functions are functions/methods that accept more than one signature. // Classes & Structs class Student { public: Student(char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Student (long NewNo, char NewName[] = "", bool NewGender = MALE); ~Student(void); }; void Display(char Message[] = ""); void Set (char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Display, Set, & Both Constructors Are Overloaded 39 39
40 Optional & Default Arguments Default Arguments are Optional Arguments One Way To Overload A Function Is To Use Optional Arguments // Classes & Structs class Student { public: Student(char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Student (long NewNo, char NewName[] = "", bool NewGender = MALE); ~Student(void); }; void Display(char Message[] = ""); void Set (char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Display, Set, & Both Constructors Contain Optional Arguments 40 40
41 41
42 Revisit Set Suppose We Would Like To Pass Method Set Any Combination Of A Character String, A Long & A Boolean Mundane Problem 42 42
43 We Could Do16 Different Functions? void Set (char NewName[], long NewNo, bool NewGender); (s,l,b) void Set (char NewName[], bool NewGender, long NewNo); (s,b,l) void Set (long NewNo, bool NewGender, char NewName[]); (l,b,s) void Set (long NewNo, char NewName[], bool NewGender); (l,s,b) void Set (bool NewGender, char NewName[], long NewNo); (b,s,l) void Set (bool NewGender, long NewNo, char NewName[]); (b,l,s) void Set (char NewName[], long NewNo); (s,l) void Set (char NewName[], bool NewGender); (s,b) void Set (long NewNo, bool NewGender); (l,b) void Set (long NewNo, char NewName[]); (l,s) void Set (bool NewGender, char NewName[]); (b,s) void Set (bool NewGender, long NewNo); (b,l) void Set (char NewName[]); (s) void Set (long NewNo); (l) void Set (bool NewGender); (b) void Set (); (-) 43
44 What Is The Least Number Of Functions That Would Be Required? Solve This Later Without Looking At The Solution void Set (char NewName[]= "", long NewNo = 0, bool NewGender = MALE); (s,l,b) (s,l) (s) ( ) void Set (char NewName[], bool NewGender, long NewNo = 0); (s,b,l) (s,b) void Set (long NewNo, bool NewGender = MALE, char NewName[] = ""); (l,b,s) (l,b) (l) void Set (long NewNo, char NewName[], bool NewGender = MALE); (l,s,b) (l,s) void Set (bool NewGender, char NewName[] = "", long NewNo = 0); (b,s,l) (b,s) (b) void Set (bool NewGender, long NewNo, char NewName[] = ""); (b,l, s) (b,l) You Would Need 6 Set Functions More Than One Set Of Solutions I Am Not Going To Code &Test This But You May If You Like? 44
45 45
46 main() { int x = 3; Student John, Sarah("Sarah", 111, FEMALE); } About Scope if (x <= 5) { Student Fred("Fred", 222, MALE"); Fred.Display(); x ++; } x --; John & Sarah Created In This Scope Fred Created In This Scope Fred Destructor Called Here! John & Sarah Created In This Scope 46
47 47
48 # define STUDENT_DIAGNOSTIC_LEVEL 4 int main (int argc, char * argv[]) { puts (" "); puts (" "); puts ("++ Class Student Added To Main - Phase 2 ++"); puts ("++ ++"); puts ("++ Writen By ++"); puts ("++ Dr. Tom Hicks YOUR NAME ++"); puts (" "); puts (" \n"); puts (" Start Of Main \n"); TestStudent(); Make The Following Changes To main COMPILE THE PROGRAM! } puts (" HitCarriageReturnToContinue(); return (0); End Of Main \n"); Change the Diagnostic Level 48
49 49
50 Add A Prototype For Get // Classes & Structs class Student { public: Student(char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Student(long NewNo, char NewName[] = "", bool NewGender = MALE); ~Student(void); void Display(char Message[] = ""); void Set (char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); bool Get (void); private: char Name[20]; long No; bool Gender; }; 50
51 Add The Documentation & Get Method maybe below Set? # pragma region STUDENT_DIAGNOSTIC_LEVEL_4 Get//=============================== ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Get // // // // Purpose : Set is an interactive function in which we will allow the user // // enter data from keyboard. // // The prompt for the First Data Member will be: // // // // Enter Name [Hit Return/Enter To Exit]: // // // // This provides the user with an opportunity to exit the function // // without entering all of the data members; after all, they may // // have entered this function by mistake. // // // // This function will explicitly returns INVALID if user chooses to // // opt out by hitting the return key; otherwise return VALID after // // the user has entered all of the data members. Your processing // // must be exactly as shown below: // // // // Enter Name [Hit Return/Enter To Exit]: Jane Doe // // Enter No : 1234 // // Enter Gender [M/F] : F // // // // Written By : Dr. Tom Hicks Environment : Windows 10 // // Date...: xx/xx/xxxx Compiler...: Visual Studio 2017 C++ // ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// 51
52 # pragma region STUDENT_DIAGNOSTIC_LEVEL_4 Get//================= bool Student::Get(void) { char Temp[200], GenderChar; Code The Get Method 1/2 maybe below Set? Reading Into Temp & Copying Into Name Prevents The User From Overflowing The Name flush_stream(stdin); printf("\nenter Name [Hit Return To Exit].: "); gets_s(temp); if (strlen(temp) == 0) return (INVALID); strncpy_s(name, Temp, 19); Name[19] = 0; flush_stream(stdin); printf("\nenter No...: "); scanf("%d", &No); Without Looking Ahead, Write The Code For This Method/Function 52
53 Code The Get Method 2/2 maybe below Set? flush_stream(stdin); printf("\nenter Sex [M/F]...: "); scanf("%c", &GenderChar); if (GenderChar == 'M') Gender = MALE; else Gender = FEMALE; flush_stream(stdin); return (VALID); } # pragma endregion 53
54 54
55 Let Us Start By Making A Copy Of The Test Code For Diagnostic Level 1 Make These Changes # pragma region STUDENT_DIAGNOSTIC_LEVEL_4 Set//=========================== if (STUDENT_DIAGNOSTIC_LEVEL <= 4) { puts("\n\n"); puts("==================================================================="); puts("==================================================================="); puts("=========== Testing Get =============="); puts("=========== STUDENT_DIAGNOSTIC_LEVEL = 4 =============="); puts("==================================================================="); puts("===================================================================\n"); Student Student1, Class[4]; HitCarriageReturnToContinue(); } # pragma endregion 55
56 Let Us Start By Making A Copy Of The Test Code For Diagnostic Level 1 Make These Changes Student Student1, Student2("Pete", 1234, MALE), Class[4]; if (Student1.Get()) Student1.Display("\nStudent1:"); else puts("\nyou Chose Not To Enter Data For Student1\n"); if (Class[3].Get()) Class[3].Display("\nClass[3]:"); else puts("\nyou Chose Not To Enter Data For Class[3]\n"); HitCarriageReturnToContinue(); } # pragma endregion 56
57 Examine Output Carefully To Make Sure It Works Don t Assume String Overflow Was Prevented! -- Enter Key To Exit Worked! 57
58 58
59 # define STUDENT_DIAGNOSTIC_LEVEL 5 int main (int argc, char * argv[]) { puts (" "); puts (" "); puts ("++ Class Student Added To Main - Phase 2 ++"); puts ("++ ++"); puts ("++ Writen By ++"); puts ("++ Dr. Tom Hicks YOUR NAME ++"); puts (" "); puts (" \n"); puts (" Start Of Main \n"); TestStudent(); Make The Following Changes To main COMPILE THE PROGRAM! } puts (" HitCarriageReturnToContinue(); return (0); End Of Main \n"); Change the Diagnostic Level 59
60 60
61 // Classes & Structs class Student { public: Student(char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Student(long NewNo, char NewName[] = "", bool NewGender = MALE); ~Student(void); void Display(char Message[] = ""); void Set (char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); bool Get (void); void Display50(void); private: char Name[20]; long No; bool Gender; }; Add A Prototype For Display50 61
62 Add The Documentation & Display50 Method maybe below Get? # pragma region STUDENT_DIAGNOSTIC_LEVEL_5 Display50//========================== ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Display50 // // // // Purpose : This is nothing more than a diagnostic display utility that will // // display the most important 50 characters of the class. We will // // develop several such utilities. Selecting the items to display // // will often be tough in a class with 100 data members, but it is // // quite easy for this class. This function uses puts & printf. // // // // There will be no line feed. The format is to be [32 char for // // Name, 2 blanks, 8 char for No, 2 blanks, and the specified // // Gender {i.e. Male or Female}. // // // // // // // // Jane Doe Female // // // // // // Written By : Dr. Tom Hicks Environment : Windows 10 // // Date...: xx/xx/xxxx Compiler...: Visual Studio 2017 C++ // ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// ostream & operator << (ostream & OutputStream, Student S) { } # pragma endregion 62
63 Code The << Overload Method maybe below Set? ostream & operator << (ostream & OutputStream, Student S) { char TempName[50]; strncpy(tempname, P.Name, 31); TempName[31] = 0; flush_stream(stdout); OutputStream << setw(32) << left << TempName; OutputStream << " " << setw(8) << P.No << " "; if (P.Gender == FEMALE) OutputStream << "Female "; else OutputStream << "Male "; return (OutputStream); } # pragma endregion 63
64 64
65 Let Us Start By Making A Copy Of The Test Code For Diagnostic Level 1 Make These Changes # pragma region STUDENT_DIAGNOSTIC_LEVEL_5 Set//=========================== if (STUDENT_DIAGNOSTIC_LEVEL <= 5) { puts("\n\n"); puts("==================================================================="); puts("==================================================================="); puts("=========== Testing Display50 =============="); puts("=========== STUDENT_DIAGNOSTIC_LEVEL = 5 =============="); puts("==================================================================="); puts("===================================================================\n"); Student Student2("Pete", , MALE), Student5(5555, "Jane", FEMALE); HitCarriageReturnToContinue(); } # pragma endregion 65
66 Let Us Start By Making A Copy Of The Test Code For Diagnostic Level 1 Make These Changes Student Student2("Pete", , MALE), Student5(5555, "Jane", FEMALE); puts(" "); puts (" "); puts (" "); printf (" "); Student2.Display50(); puts (" "); puts (" "); printf (" "); Students5.Display50(); puts (" "); HitCarriageReturnToContinue(); } # pragma endregion 66
67 Examine Output Carefully To Make Sure It Works Don t Assume 67
68 68
69 # define STUDENT_DIAGNOSTIC_LEVEL 6 int main (int argc, char * argv[]) { puts (" "); puts (" "); puts ("++ Class Student Added To Main - Phase 2 ++"); puts ("++ ++"); puts ("++ Writen By ++"); puts ("++ Dr. Tom Hicks YOUR NAME ++"); puts (" "); puts (" \n"); puts (" Start Of Main \n"); TestStudent(); Make The Following Changes To main COMPILE THE PROGRAM! } puts (" HitCarriageReturnToContinue(); return (0); End Of Main \n"); Change the Diagnostic Level 69
70 70
71 // Classes & Structs class Student { public: Student(char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Student(long NewNo, char NewName[] = "", bool NewGender = MALE); ~Student(void); void Display(char Message[] = ""); void Set (char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); bool Get (void); void Display50(void); friend ostream & operator << (ostream & OutputStream, Student S); private: char Name[20]; long No; bool Gender; }; Add A Prototype For Overload Of << Note The Friend 71
72 Add The Documentation & << Overload maybe below Get? # pragma region STUDENT_DIAGNOSTIC_LEVEL_6 cout//=============================== ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // << Overload // // // // Purpose : This is nothing more than a diagnostic display utility that will // // display the most important 50 characters of the class. We will // // develop several such utilities. Selecting the items to display // // will often be tough in a class with 100 data members, but it is // // quite easy for this class. This function uses cout. // // // // There will be no line feed. The format is to be [32 char for // // Name, 2 blanks, 8 char for No, 2 blanks, and the specified // // Gender {i.e. Male or Female}. // // // // // // // // Jane Doe Female // // // // // // Written By : Dr. Tom Hicks Environment : Windows 10 // // Date...: xx/xx/xxxx Compiler...: Visual Studio 2017 C++ // ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// void Student::Display50(void) { } # pragma endregion 72
73 Code The << Overload maybe below Display50? # pragma region STUDENT_DIAGNOSTIC_LEVEL_6 cout//================== ostream & operator << (ostream & OutputStream, Student S) { char TempName[50]; strncpy_s(tempname, S.Name, 31); TempName[31] = 0; flush_stream(stdout); OutputStream << setw(32) << left << TempName; OutputStream << " " << setw(8) << S.No << " "; if (S.Gender == FEMALE) OutputStream << "Female "; else OutputStream << "Male "; return (OutputStream); } # pragma endregion# pragma endregion Be Able To Do But Do Not Memorize - Not On Exam 73
74 74
75 Let Us Start By Making A Copy Of The Test Code For Diagnostic Level 5 Make These Changes # pragma region STUDENT_DIAGNOSTIC_LEVEL_6 Cout//========================= if (STUDENT_DIAGNOSTIC_LEVEL <= 6) { puts("\n\n"); puts("==================================================================="); puts("==================================================================="); puts("=========== Testing << Overload =============="); puts("=========== STUDENT_DIAGNOSTIC_LEVEL = 6 =============="); puts("==================================================================="); puts("===================================================================\n"); Student Student2("Pete", , MALE), Student5(5555, "Jane", FEMALE); HitCarriageReturnToContinue(); } # pragma endregion 75
76 Let Us Start By Making A Copy Of The Test Code For Diagnostic Level 1 Make These Changes Student Student2("Pete", , MALE), Student5(5555, "Jane", FEMALE); puts(" "); puts(" "); puts(" "); cout << " " << Student2 << " " << endl; puts(" "); cout << " " << Student5 << " " << endl; puts(" "); HitCarriageReturnToContinue(); } # pragma endregion 76
77 Examine Output Carefully To Make Sure It Works Don t Assume 77
78 78
79 # define STUDENT_DIAGNOSTIC_LEVEL 7 int main (int argc, char * argv[]) { puts (" "); puts (" "); puts ("++ Class Student Added To Main - Phase 2 ++"); puts ("++ ++"); puts ("++ Writen By ++"); puts ("++ Dr. Tom Hicks YOUR NAME ++"); puts (" "); puts (" \n"); puts (" Start Of Main \n"); TestStudent(); Make The Following Changes To main COMPILE THE PROGRAM! } puts (" HitCarriageReturnToContinue(); return (0); End Of Main \n"); Change the Diagnostic Level 79
80 80
81 // Classes & Structs class Student { public: Student(char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Student(long NewNo, char NewName[] = "", bool NewGender = MALE); ~Student(void); void Display(char Message[] = ""); void Set (char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); bool Get (void); void Display50(void); long int Key(void); Add A Prototype For Key friend ostream & operator << (ostream & OutputStream, Student S); private: char Name[20]; long No; bool Gender; }; Write A Function Key That Explicitly Returns A Long Integer 81
82 Add The Documentation & Code Key maybe below Get? # pragma region STUDENT_DIAGNOSTIC_LEVEL_7 Key//================================ ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Key // // // // Purpose : Explicitly Return a long integer that represents this student. // // In some classes it will be difficult to determine which long // // integer best represents the object; in this class we have but // // one. Explicitly return the No. // // // // Since the data members are generally private, it is not at all // // to have several accessor methods // // // // Written By : Dr. Tom Hicks Environment : Windows 10 // // Date...: xx/xx/xxxx Compiler...: Visual Studio 2017 C++ // ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// long Student::Key(void) { return (No); } # pragma endregion 82
83 83
84 Let Us Start By Making A Copy Of The Test Code For Diagnostic Level 6 Make These Changes # pragma region STUDENT_DIAGNOSTIC_LEVEL_7 Cout//========================= if (STUDENT_DIAGNOSTIC_LEVEL <= 7) { puts("\n\n"); puts("==================================================================="); puts("==================================================================="); puts("=========== Testing Key =============="); puts("=========== STUDENT_DIAGNOSTIC_LEVEL = 7 =============="); puts("==================================================================="); puts("===================================================================\n"); Student Student2("Pete", , MALE), Student5(5555, "Jane", FEMALE); printf("student2.key() = %ld\n", Student2.Key()); printf("student5.key() = %ld\n", Student5.Key()); HitCarriageReturnToContinue(); } # pragma endregion 84
85 Examine Output Carefully To Make Sure It Works Don t Assume 85
86 86
87 Accessors Accessor - A method that examines, but not change the state of an object. // Classes & Structs class Student { public: Student(char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Student(long NewNo, char NewName[] = "", bool NewGender = MALE); ~Student(void); void Display(char Message[] = ""); void Set(char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); bool Get(void); void Display50(void); long Key(void); friend ostream & operator << (ostream & OutputStream, Student S); 87 87
88 Mutators Mutator- A method that changes the state of an object. // Classes & Structs class Student { public: Student(char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); Student(long NewNo, char NewName[] = "", bool NewGender = MALE); ~Student(void); void Display(char Message[] = ""); void Set(char NewName[] = "", long int NewNo = 0, bool NewGender = MALE); bool Get(void); void Display50(void); long Key(void); friend ostream & operator << (ostream & OutputStream, Student S); 88 88
RECOMMENDATION. Don't Write Entire Programs Unless You Want To Spend 3-10 Times As Long Doing Labs! Write 1 Function - Test That Function!
1 2 RECOMMENDATION Don't Write Entire Programs Unless You Want To Spend 3-10 Times As Long Doing Labs! Write 1 Function - Test That Function! 2 Function Overloading C++ provides the capability of Using
More information# 1. Objectives. Objectives. 13.Visual Studio Projects. C/C++ The array is an Aggregate!
1 2 Objectives 1. Agregates 2. Structs 3. Introduction To Classes 4. Constructor 5. Destructor 6. Function Overloading 7. Default Arguments 8. Accessors & Mutators 9. ADT Abstract Data Types 10. Operator
More informationOOP- 4 Templates & Memory Management Print Only Pages 1-5 Individual Assignment Answers To Questions 10 Points - Program 15 Points
OOP-4-Templates-Memory-Management-HW.docx CSCI 2320 Initials P a g e 1 If this lab is an Individual assignment, you must do all coded programs on your own. You may ask others for help on the language syntax,
More informationC:\Temp\Templates. Download This PDF From The Web Site
11 2 2 2 3 3 3 C:\Temp\Templates Download This PDF From The Web Site 4 5 Use This Main Program Copy-Paste Code From The Next Slide? Compile Program 6 Copy/Paste Main # include "Utilities.hpp" # include
More information2 2
1 2 2 3 3 C:\Temp\Templates 4 5 Use This Main Program 6 # include "Utilities.hpp" # include "Student.hpp" Copy/Paste Main void MySwap (int Value1, int Value2); int main(int argc, char * argv[]) { int A
More informationOOP- 5 Stacks Individual Assignment 35 Points
OOP-5-Stacks-HW.docx CSCI 2320 Initials P a g e 1 If this lab is an Individual assignment, you must do all coded programs on your own. You may ask others for help on the language syntax, but you must organize
More informationFunctions & Memory Maps Review C Programming Language
Functions & Memory Maps Review C Programming Language Data Abstractions CSCI-2320 Dr. Tom Hicks Computer Science Department Constants c 2 What Is A Constant? Constant a Value that cannot be altered by
More informationFunction Terminology
OOP-1-Review-HW-(Part C).docx CSCI 2320 Initials P a g e 1 Print Name Time Required =. Hrs. Signature (pledged) Function Terminology 1] A C_?_ is a Value that cannot be altered by the program during normal
More informationG52CPP C++ Programming Lecture 9
G52CPP C++ Programming Lecture 9 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last lecture const Constants, including pointers The C pre-processor And macros Compiling and linking And
More informationPIC 10A. Final Review: Part I
PIC 10A Final Review: Part I Final exam The final exam is worth 30% of your grade, same weight as 2 midterms. Could be 50% if grading option 2 turns out better for you. Length is also roughly 2 midterms
More informationFast Introduction to Object Oriented Programming and C++
Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming
More informationMakefiles Makefiles should begin with a comment section of the following form and with the following information filled in:
CS 215 Fundamentals of Programming II C++ Programming Style Guideline Most of a programmer's efforts are aimed at the development of correct and efficient programs. But the readability of programs is also
More informationLecture 7. Log into Linux New documents posted to course webpage
Lecture 7 Log into Linux New documents posted to course webpage Coding style guideline; part of project grade is following this Homework 4, due on Monday; this is a written assignment Project 1, due next
More informationOperator overloading
1 Introduction 2 The copy constructor 3 Operator Overloading 4 Eg 1: Adding two vectors 5 The -> operator 6 The this pointer 7 Overloading = 8 Unary operators 9 Overloading for the matrix class 10 The
More informationG52CPP C++ Programming Lecture 7. Dr Jason Atkin
G52CPP C++ Programming Lecture 7 Dr Jason Atkin 1 This lecture classes (and C++ structs) Member functions inline functions 2 Last lecture: predict the sizes 3 #pragma pack(1) #include struct A
More informationTopic 10: Introduction to OO analysis and design
Topic 10: Introduction to OO analysis and design Learning Outcomes Upon successful completion of this topic you will be able to: design classes define class member variables and functions explain public
More informationOOP-8-DLList-1-HW.docx CSCI 2320 Initials Page 1
OOP-8-DLList-1-HW.docx CSCI 2320 Initials Page 1 If this lab is an Individual assignment, you must do all coded programs on your own. You may ask others for help on the language syntax, but you must organize
More informationServer Component of the Chat Room Lab
Chat Room Server Dr. Tom Hicks - Trinity University Page 1 of 41 Server Component of the Chat Room Lab This lab is designed to show students how they may can do socket programming in a step by step process
More informationIII. Classes (Chap. 3)
III. Classes III-1 III. Classes (Chap. 3) As we have seen, C++ data types can be classified as: Fundamental (or simple or scalar): A data object of one of these types is a single object. int, double, char,
More informationHomework 5. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine
Homework 5 Yuji Shimojo CMSC 330 Instructor: Prof. Reginald Y. Haseltine July 13, 2013 Question 1 Consider the following Java definition of a mutable string class. class MutableString private char[] chars
More informationDistributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes
Distributed Real-Time Control Systems Lecture 17 C++ Programming Intro to C++ Objects and Classes 1 Bibliography Classical References Covers C++ 11 2 What is C++? A computer language with object oriented
More informationCh. 12: Operator Overloading
Ch. 12: Operator Overloading Operator overloading is just syntactic sugar, i.e. another way to make a function call: shift_left(42, 3); 42
More informationFunction Overloading
Function Overloading C++ supports writing more than one function with the same name but different argument lists How does the compiler know which one the programmer is calling? They have different signatures
More informationMARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012
MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012 Instructor: K. S. Booth Time: 70 minutes (one hour ten minutes)
More informationPointers & Dynamic Memory Review C Pointers Introduce C++ Pointers
Pointers & Dynamic Memory Review C Pointers Introduce C++ Pointers Data Abstractions CSCI-2320 Dr. Tom Hicks Computer Science Department c http://carme.cs.trinity.edu/ thicks/2320/schedule.html http://carme.cs.trinity.edu/thicks/2320/schedule.html
More informationIS0020 Program Design and Software Tools Midterm, Fall, 2004
IS0020 Program Design and Software Tools Midterm, Fall, 2004 Name: Instruction There are two parts in this test. The first part contains 22 questions worth 40 points you need to get 20 right to get the
More informationCSE 333 Midterm Exam July 24, Name UW ID#
Name UW ID# There are 6 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,
More informationUniversity of Maryland Baltimore County. CMSC 202 Computer Science II. Fall Mid-Term Exam. Sections
University of Maryland Baltimore County CMSC 202 Computer Science II Fall 2004 Mid-Term Exam Sections 0201 0206 Lecture Hours: Monday Wednesday 5:30 PM 6:45 PM Exam Date: Wednesday 10/20/2004 Exam Duration:
More informationComputer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons
Computer Programming Basic Control Flow - Loops Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Objectives To learn about the three types of loops: while for do To avoid infinite
More informationLab 2: ADT Design & Implementation
Lab 2: ADT Design & Implementation By Dr. Yingwu Zhu, Seattle University 1. Goals In this lab, you are required to use a dynamic array to design and implement an ADT SortedList that maintains a sorted
More informationCircle all of the following which would make sense as the function prototype.
Student ID: Lab Section: This test is closed book, closed notes. Points for each question are shown inside [ ] brackets at the beginning of each question. You should assume that, for all quoted program
More informationC/C++ Text File Functions
1 2 3 C/C++ Text File Functions fopen opens a text file. fclose closes a text file. feof detects end-of-file marker in a file. fscanf reads formatted input from a file. fprintf prints formatted output
More informationCS 251 Intermediate Programming Methods and Classes
CS 251 Intermediate Programming Methods and Classes Brooke Chenoweth University of New Mexico Fall 2018 Methods An operation that can be performed on an object Has return type and parameters Method with
More informationCS 251 Intermediate Programming Methods and More
CS 251 Intermediate Programming Methods and More Brooke Chenoweth University of New Mexico Spring 2018 Methods An operation that can be performed on an object Has return type and parameters Method with
More informationpointers & references
pointers & references 1-22-2013 Inline Functions References & Pointers Arrays & Vectors HW#1 posted due: today Quiz Thursday, 1/24 // point.h #ifndef POINT_H_ #define POINT_H_ #include using
More informationFundamentals of Programming Session 24
Fundamentals of Programming Session 24 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines
More informationCS 103 Unit 10 Slides
1 CS 103 Unit 10 Slides C++ Classes Mark Redekopp 2 Object-Oriented Programming Model the application/software as a set of objects that interact with each other Objects fuse data (i.e. variables) and functions
More informationOOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.
OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.
More informationFriend Functions and Friend Classes
Friend Functions and Friend Classes C++ allows you to declare another class to be a friend of the current class to make it easier to access variables. OOP purists have criticized this feature as weakening
More informationLab: Supplying Inputs to Programs
Steven Zeil May 25, 2013 Contents 1 Running the Program 2 2 Supplying Standard Input 4 3 Command Line Parameters 4 1 In this lab, we will look at some of the different ways that basic I/O information can
More informationCE221 Programming in C++ Part 1 Introduction
CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab
More informationDue Date: See Blackboard
Source File: ~/2315/45/lab45.(C CPP cpp c++ cc cxx cp) Input: under control of main function Output: under control of main function Value: 4 Integer data is usually represented in a single word on a computer.
More informationCSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010
CSE 374 Programming Concepts & Tools Hal Perkins Spring 2010 Lecture 19 Introduction ti to C++ C++ C++ is an enormous language: g All of C Classes and objects (kind of like Java, some crucial differences)
More informationCS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:
Page 1 of 10 Name: Email ID: You MUST write your name and e-mail ID on EACH page and bubble in your userid at the bottom of EACH page including this page and page 10. If you do not do this, you will receive
More informationCommon Misunderstandings from Exam 1 Material
Common Misunderstandings from Exam 1 Material Kyle Dewey Stack and Heap Allocation with Pointers char c = c ; char* p1 = malloc(sizeof(char)); char** p2 = &p1; Where is c allocated? Where is p1 itself
More informationInstalling and Using Dev-C++
Installing and Using Dev-C++ 1. Installing Dev-C++ Orwell Dev-C++ is a professional C++ IDE, but not as big and complex as Visual Studio. It runs only on Windows; both Windows 7 and Windows 8 are supported.
More informationIntermediate Programming & Design (C++) Classes in C++
Classes in C++ A class is a data type similar to a C structure. It includes various local data (called data members) together with constructors, destructors and member functions. All of them are called
More informationCS3157: Advanced Programming. Outline
CS3157: Advanced Programming Lecture #12 Apr 3 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline Intro CPP Boring stuff: Language basics: identifiers, data types, operators, type conversions, branching
More informationCS 103 Unit 10 Slides
1 CS 103 Unit 10 Slides C++ Classes Mark Redekopp 2 Object-Oriented Programming Model the application/software as a set of objects that interact with each other Objects fuse data (i.e. variables) and functions
More informationCpt S 122 Data Structures. Introduction to C++ Part II
Cpt S 122 Data Structures Introduction to C++ Part II Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Objectives Defining class with a member function
More informationMidterm Examination. Instructor: Gary Chan Date: Saturday, 23 October 2010 Time: 2:30pm 4:00pm Venue: LTC
THE HONG KONG UNIVERSITY OF SCIENCE & TECHNOLOGY Department of Computer Science & Engineering COMP 152: Object-Oriented Programming and Data Structures Fall 2010 Midterm Examination Instructor: Gary Chan
More informationIntroduction to C++ 2. A Simple C++ Program. A C++ program consists of: a set of data & function definitions, and the main function (or driver)
Introduction to C++ 1. General C++ is an Object oriented extension of C which was derived from B (BCPL) Developed by Bjarne Stroustrup (AT&T Bell Labs) in early 1980 s 2. A Simple C++ Program A C++ program
More informationOBJECT ORIENTED PROGRAMMING USING C++
OBJECT ORIENTED PROGRAMMING USING C++ Overview of C++ Overloading Overloading occurs when the same operator or function name is used with different signatures Both operators and functions can be overloaded
More informationCall The Project Dynamic-Memory
1 2 2 Call The Project Dynamic-Memory 4 4 Copy-Paste Main # include "Utilities.hpp" int main(int argc, char * argv[]) { short int *PtrNo; (*PtrNo) = 5; printf ("(*PtrNo) = %d\n", (*PtrNo)); } getchar();
More informationReview: C++ Basic Concepts. Dr. Yingwu Zhu
Review: C++ Basic Concepts Dr. Yingwu Zhu Outline C++ class declaration Constructor Overloading functions Overloading operators Destructor Redundant declaration A Real-World Example Question #1: How to
More informationDiscussion 1E. Jie(Jay) Wang Week 10 Dec.2
Discussion 1E Jie(Jay) Wang Week 10 Dec.2 Outline Dynamic memory allocation Class Final Review Dynamic Allocation of Memory Recall int len = 100; double arr[len]; // error! What if I need to compute the
More informationl A class in C++ is similar to a structure. - It allows you to define a new (composite) data type. l A class contains the following: - variables AND
Introduction to Classes 13.2 The Class Unit 4 Chapter 13 CS 2308 Fall 2016 Jill Seaman 1 l A class in C++ is similar to a structure. - It allows you to define a new (composite) data type. l A class contains
More informationLab 12 Object Oriented Programming Dr. John Abraham
Lab 12 Object Oriented Programming Dr. John Abraham We humans are very good recognizing and working with objects, such as a pen, a dog, or a human being. We learned to categorize them in such a way that
More informationUniversity of Maryland Baltimore County. CMSC 202 Computer Science II. Fall Mid-Term Exam. Sections
University of Maryland Baltimore County CMSC 202 Computer Science II Fall 2005 Mid-Term Exam Sections 0201 0206 Lecture Hours: Monday Wednesday 5:30 PM 6:45 PM Exam Date: Wednesday 3/16/05 Exam Duration:
More informationIntroduction to Programming session 24
Introduction to Programming session 24 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2010 These slides are created using Deitel sslides Sharif Universityof Technology Outlines Introduction
More informationCS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.
CS61C Machine Structures Lecture 3 Introduction to the C Programming Language 1/23/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L03 Introduction to C (1) Administrivia
More informationUniversity of Illinois at Urbana-Champaign Department of Computer Science. First Examination
University of Illinois at Urbana-Champaign Department of Computer Science First Examination CS 225 Data Structures and Software Principles Spring 2007 7p-9p, Thursday, March 1 Name: NetID: Lab Section
More informationBOOLEAN EXPRESSIONS CONTROL FLOW (IF-ELSE) INPUT/OUTPUT. Problem Solving with Computers-I
BOOLEAN EXPRESSIONS CONTROL FLOW (IF-ELSE) INPUT/OUTPUT Problem Solving with Computers-I Announcements HW02: Complete (individually)using dark pencil or pen, turn in during lab section next Wednesday Please
More information(5 2) Introduction to Classes in C++ Instructor - Andrew S. O Fallon CptS 122 (February 7, 2018) Washington State University
(5 2) Introduction to Classes in C++ Instructor - Andrew S. O Fallon CptS 122 (February 7, 2018) Washington State University Key Concepts Function templates Defining classes with member functions The Rule
More informationCpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input
CpSc Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input Overview For this lab, you will use: one or more of the conditional statements explained below scanf() or fscanf() to read
More informationAbstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles
Abstract Data Types (ADTs) CS 247: Software Engineering Principles ADT Design An abstract data type (ADT) is a user-defined type that bundles together: the range of values that variables of that type can
More informationChapter 1 Getting Started
Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different
More informationFinal CSE 131B Spring 2004
Login name Signature Name Student ID Final CSE 131B Spring 2004 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 (25 points) (24 points) (32 points) (24 points) (28 points) (26 points) (22 points)
More informationECE 462 Exam 1. 6:30-7:30PM, September 22, 2010
ECE 462 Exam 1 6:30-7:30PM, September 22, 2010 I will not receive nor provide aid to any other student for this exam. Signature: You must sign here. Otherwise, the exam is not graded. This exam is printed
More informationAIMS Embedded Systems Programming MT 2017
AIMS Embedded Systems Programming MT 2017 Object-Oriented Programming with C++ Daniel Kroening University of Oxford, Computer Science Department Version 1.0, 2014 Outline Classes and Objects Constructors
More informationIntroduction to Programming using C++
Introduction to Programming using C++ Lecture One: Getting Started Carl Gwilliam gwilliam@hep.ph.liv.ac.uk http://hep.ph.liv.ac.uk/~gwilliam/cppcourse Course Prerequisites What you should already know
More informationG52CPP C++ Programming Lecture 14. Dr Jason Atkin
G52CPP C++ Programming Lecture 14 Dr Jason Atkin 1 Last Lecture Automatically created methods: A default constructor so that objects can be created without defining a constructor A copy constructor used
More informationACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1
ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1 Due to CMS by Tuesday, February 14. Social networking has caused a return of the dot-com madness. You want in on the easy money, so you have decided to make
More informationLecture 2, September 4
Lecture 2, September 4 Intro to C/C++ Instructor: Prashant Shenoy, TA: Shashi Singh 1 Introduction C++ is an object-oriented language and is one of the most frequently used languages for development due
More informationAn Introduction to C++
An Introduction to C++ Introduction to C++ C++ classes C++ class details To create a complex type in C In the.h file Define structs to store data Declare function prototypes The.h file serves as the interface
More informationTopics. Constructor. Constructors
Topics 1) How can we initialize an object when it's created? 2) How can we do things when an object is destroyed? 3) How can we write functions with different parameters? Slides #11 - Text 7.6-7.7 Constructors
More informationKapil Sehgal PGT Computer. Science Ankleshwar Gujarat
Classes Chapter 4 Classes and Objects Data Hiding and Encapsulation Function in a Class Using Objects Static Class members Classes Class represents a group of Similar objects A class is a way to bind the
More informationCMPT 117: Tutorial 1. Craig Thompson. 12 January 2009
CMPT 117: Tutorial 1 Craig Thompson 12 January 2009 Administrivia Coding habits OOP Header Files Function Overloading Class info Tutorials Review of course material additional examples Q&A Labs Work on
More informationCSC111 Computer Science II
CSC111 Computer Science II Lab 1 Getting to know Linux Introduction The purpose of this lab is to introduce you to the command line interface in Linux. Getting started In our labs If you are in one of
More informationCSE 5A Introduction to Programming I (C) Homework 4
CSE 5A Introduction to Programming I (C) Homework 4 Read Chapter 7 Due: Friday, October 26 by 6:00pm All programming assignments must be done INDIVIDUALLY by all members of the class. Start early to ensure
More informationA506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).
A506 / C201 Computer Programming II Placement Exam Sample Questions For each of the following, choose the most appropriate answer (2pts each). 1. Which of the following functions is causing a temporary
More informationCMSC 341 Lecture 7 Lists
CMSC 341 Lecture 7 Lists Today s Topics Linked Lists vs Arrays Nodes Using Linked Lists Supporting Actors (member variables) Overview Creation Traversal Deletion UMBC CMSC 341 Lists 2 Linked Lists vs Arrays
More informationNote 11/13/2014. They are like those i s, j s, and temp s that appear and disappear when the function starts and finishes...
CISC 2000 Computer Science II Fall, 2014 Note 11/13/2014 1 Review of operator overloading (a) Lab class: take-away ############################ # Pass-by-value parameters # ############################
More informationOOP-1-Review-HW-(Part B).docx CSCI 2320 Initials P a g e 1. Print Name Time Required =. Hrs. Signature (pledged) Static Array Review
OOP-1-Review-HW-(Part B).docx CSCI 2320 Initials P a g e 1 Print Name Time Required =. Hrs. Signature (pledged) Static Array Review 1] Write the line of C/C++ code to create an array, called Nos1, which
More informationdynamically allocated memory char* x = new char; int* x = new int[n]; ???...?
dynamically allocated memory char* x = new char; yields a memory address 1. allocates memory for a char 2. declares a pointer to a char 3. sets pointer to memory address x pointer? memory (1 byte) int*
More informationThe American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010
The American University in Cairo Computer Science & Engineering Department CSCE 106-08 Dr. KHALIL Exam II Spring 2010 Last Name :... ID:... First Name:... Form - I EXAMINATION INSTRUCTIONS * Do not turn
More informationCS 247: Software Engineering Principles. ADT Design
CS 247: Software Engineering Principles ADT Design Readings: Eckel, Vol. 1 Ch. 7 Function Overloading & Default Arguments Ch. 12 Operator Overloading U Waterloo CS247 (Spring 2017) p.1/17 Abstract Data
More informationFundamentals of Programming CS-110. Lecture 2
Fundamentals of Programming CS-110 Lecture 2 Last Lab // Example program #include using namespace std; int main() { cout
More informationCOMP 2355 Introduction to Systems Programming
COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Today Class syntax, Constructors, Destructors Static methods Inheritance, Abstract
More informationCS304 Object Oriented Programming Final Term
1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing
More informationIntroduction to Classes
Introduction to Classes Procedural and Object-Oriented Programming Procedural and Object-Oriented Programming Procedural programming focuses on the process/actions that occur in a program Object-Oriented
More informationScope. Scope is such an important thing that we ll review what we know about scope now:
Scope Scope is such an important thing that we ll review what we know about scope now: Local (block) scope: A name declared within a block is accessible only within that block and blocks enclosed by it,
More informationReview Questions for Final Exam
CS 102 / ECE 206 Spring 11 Review Questions for Final Exam The following review questions are similar to the kinds of questions you will be expected to answer on the Final Exam, which will cover LCR, chs.
More information377 Student Guide to C++
377 Student Guide to C++ c Mark Corner January 21, 2004 1 Introduction In this course you will be using the C++ language to complete several programming assignments. Up to this point we have only provided
More informationLearning Recursion. Recursion [ Why is it important?] ~7 easy marks in Exam Paper. Step 1. Understand Code. Step 2. Understand Execution
Recursion [ Why is it important?] ~7 easy marks in Exam Paper Seemingly Different Coding Approach In Fact: Strengthen Top-down Thinking Get Mature in - Setting parameters - Function calls - return + work
More informationl Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)
Final Exam Exercises Chapters 1-7 + 11 Write C++ code to: l Determine if a number is odd or even CS 2308 Fall 2016 Jill Seaman l Determine if a number/character is in a range - 1 to 10 (inclusive) - between
More informationCopying Data. Contents. Steven J. Zeil. November 13, Destructors 2
Steven J. Zeil November 13, 2013 Contents 1 Destructors 2 2 Copy Constructors 11 2.1 Where Do We Use a Copy Constructor? 12 2.2 Compiler-Generated Copy Constructors............................................
More informationC How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. 1
C How to Program, 6/e 1 Structures : Aggregate data types are built using elements of other types struct Time { int hour; int minute; Members of the same structure must have unique names. Two different
More informationCS201- Introduction to Programming Current Quizzes
CS201- Introduction to Programming Current Quizzes Q.1 char name [] = Hello World ; In the above statement, a memory of characters will be allocated 13 11 12 (Ans) Q.2 A function is a block of statements
More informationSpring 2008 Data Structures (CS301) LAB
Spring 2008 Data Structures (CS301) LAB Objectives The objectives of this LAB are, o Enabling students to implement Singly Linked List practically using c++ and adding more functionality in it. o Enabling
More information