Welcome to CAVI, the Cisco Academy for the Vision Impaired. Course Fees Linux Wiki HTML Wiki Documentation Index PmWiki FAQ |
Chapter5ComingSoon5.1.1Image 1: This image shows three circles interlinked to each other, in each of the circles is the written text letters, signs and numbers. 5.1.2Image 1: This image shows three coloured circles, green, orange and blue respectively with the words flour in the green circle, milk in the orange and spices in the blue. Each circle is inside a bowl with an arrow pointing downwards from the bottom of the bowl to the word cake. 5.1.3Image 1: This image shows three columns of rectangles. The first column has one rectangle which is coloured purple with the word vehicles written in white text, the second column has four orange rectangles with the words written from top to bottom as follows: land vehicles, water vehicles, air vehicles and space vehicles, each of these rectangles are attached to the purple rectangle by a straight orange line. The third column has three blue rectangles with words written from top to bottom as follows: wheeled vehicles, tracked vehicles and hovercrafts, each of the blue rectangles are also attached to the first orange rectangle by a straight blue line. 5.1.4Image 1: This image shows three columns of rectangles. The first column has one rectangle which is coloured purple with the word animals written in white text, the second column has five orange rectangles with the words written from top to bottom as follows: mammals, reptiles, birds, fish, and amphibians, each of these rectangles are attached to the purple rectangle by a straight orange line. The third column has two blue rectangles with the words wild animals and domesticated animals written in them respectively, each of these rectangles are also attached to the first orange rectangle by a blue straight line. 5.1.5Image 1: This image shows sixteen thumbnail pictures of different types of fruit, arranged in rows of four. the rows contain the following fruits: Row 1: cherries, peaches, plums, and rock melon. Row 2: kiwi-fruit, blueberries, watermelon, and honey-dew melon. Row 3: blood orange, figs, mandarin, and strawberries. Row 4: apple, persimmon, red grapes, and blackberries. 5.1.6Image 1: This image shows the family tree of the Royal Pedigree of England. 5.1.7Image 1: This image is showing a 1950s pink and white Cadillac car. 5.1.8Image 1: This image shows an example of how to define a class and create an object in C++, this has been written out below. Class OurClass {}; 5.1.9Image 1: This is another example of how to define a class and create an object in C++, this has also been written out below. OurClass our_object; 5.2.1Image 1: This image shows a single stack of Australian 1 dollar coins in a column. 5.2.2Image 1: This image shows an example of a stack (also known as a LIFO (Last In First Out)) which has been written in C++ below. int stack[100]; 5.2.3Image 1: This image shows an example of a stack pointer, which has been written out in C++ below. int SP = 0; 5.2.4Image 1: This image shows an example of a new stack function called push, which has been written out in C++ below. void push(int value){ stack[SP++] = value; } 5.2.5Image 1: This image shows an example of a new stack function called pop, which has been written out in C++ below. int pop(void){ return stack[--SP]; } 5.2.6Image 1: This image shows a stack program, which is written out below in C++. #include <iostream> using namespace std; int stack[100]; int SP = 0; void push(int value) { stack[SP++] = value; } int pop(void){ return stack[--SP]; } int main(void) { push(3); push(2); push(1); cout<<pop()<<endl; cout<<pop()<<endl; cout<<pop()<<endl; return 0; } 5.2.7Image 1: This image shows four stacks of Australian one dollar coins, with each stack being bigger than the previous stack of gold coins. 5.2.8Image 1: This image shows an example of a program using a vector as the stack's storage and the int variable as the stack pointer. This has been written out below in C++. class Stack{ int stackstore[100]; int SP; }; 5.2.9Image 1: This image shows an example of a program using a vector as the stack's storage and the int variable as the stack pointer, which has been updated. this has been written out below in C++. class Stack{ private: int stackstore[100]; int SP; }; 5.2.10Image 1: This image shows another example of a program using a vector as the stack's storage and the int variable as the stack pointer, which has been updated. this has been written out below in C++. class Stack{ private: int stackstore[100]; int SP; public: void push (int value); int pop(void){ return stackstore[--SP]; } }; 5.2.11Image 1: This image shows another example of a program using a vector as the stack's storage and the int variable as the stack pointer, which has been updated, this has been written out below in C++. class Stack{ private: int stackstore[100]; int SP; public: void push (int value); int pop(void){ return stackstore[--SP]; } }; void stack::push(int value){ stackstore[sp++] = value; } 5.2.12Image 1: This image shows another example of a program using a vector as the stack's storage and the int variable as the stack pointer, which has been updated, this is written out below in C++. class Stack{ private: int stackstore[100]; int SP; public: Stack(void) {SP = 0;} void push (int value); int pop(void){ return stackstore[--SP]; } }; void stack::push(int value){ stackstore[sp++] = value; } 5.2.13Image 1: This image shows another example of a program using a vector as the stack's storage and the int variable as the stack pointer, which has been updated. This has been written out below in C++. #include<iostream> using namespace std; int main(void){ Stack little_stack, another_stack, funny_stack; Little_stack.push(1); another_stack.push(little_stack.pop() + 1); funny_stack.push(another_stack.pop() + 2); cout<<funny_stack.pop()<<endl; return 0; } 5.2.14Image 1: This image shows an example of creating a subclass for the stack class which has been written out below in C++. class AddingStack : Stack { }; 5.2.15Image 1: This image shows another example of a program using a vector as the stack's storage and the int variable as the stack pointer, which has been updated. This has been written out below. class AddingStack : Stack{ private: int sum; public: void push (int value); int pop(void); }; 5.2.16Image 1: This image shows an example of the push function in C++, which is written out below. void AddingStack::push(int value){ sum += value; Stack += value; Stack::push(value); } 5.2.17Image 1: This image shows a new pop function, which has been written out below in C++. int AddingStack::pop(void){ int val = Stack::pop(): sum -= val; return val; } 5.2.18Image 1: This image shows how to define a new function called getSum, which has been written out below in C++. int AddingStack::getSum(void){ return sum; } 5.2.19Image 1: This image shows how to create a new class object called AddingStack, and initialise the super class constructor. this has been written out below in C++. AddingStack::AddingStack(void): Stack(){ Sum = 0; } 5.2.20Image 1: This image shows the final version of the updated program using a vector as the stack's storage and the int variable as the stack pointer. This has been written out below in C++. class AddingStack : Stack{ private: int sum; Public: AddingStack(void); void push(int value); int pop(void); int getsum(void); }; AddingStack::AddingStack(void) : Stack() { Sum = 0; } void AddingStack::push(int value){ sum += value; Stack::push(value); } int AddingStack::pop(void){ int val = Stack::pop(); sum -= val; return val; } int AddingStack::getsum(void){ return sum; } 5.2.21Image 1: This is an image of a complete program that will output 2 numbers, 45 and zero. The program has been written out below in C++. #include <iostream> using namespace std; int main(void){ AddingStack Super_stack; for(int i = 1; i < 10; i++) super_stack.push(i); cout<<super_stack.getsum()<<endl; for(int i = 1; i < 10; i++) super_stack.pop(); cout<<super_stack.getSum()<<endl; return 0; } 5.3.1Image 1: This image shows an example of class components, these have been written out below in C++. class Class{ int value; void setVal(int value); int getVal(void); }; 5.3.2Image 1: This image shows an example of Access specifiers, these have been written out below in C++. class Class{ public: void setVal(int value); int getVal(void); private: int value; }; 5.3.3Image 1: This image shows an example of creating an object, this has been written out below in C++. Class the_object; 5.3.4Image 1: This image shows an example of overriding component names in C++, this has been written out below. class Class{ public: void setVal(int value) { Class::value = value; } int getVal(void); private: int value; }; 5.3.5Image 1: This image shows an example of a pointer, which has been written out below in C++. class Class{ public: void setVal(int value) { this -> value = value; } int getval(void); private: int value; }; 5.3.6Image 1: This image shows qualifying component names in C++, these have been written out below. class Class{ public: void setVal(int value) { this -> value = value; } int getval(void); private: int value; }; int Class::getVal(void) { return value; } 5.3.7Image 1: This image shows another example of qualifying component names that have been updated, these are written out below in C++. class Class{ public: void setVal(int value) {this -> value = value; } void setVal(void) {value = -2;} int getVal(void) {return value;} private: int value; }; 5.3.8Image 1: This image shows an example of constructors in C++, this has been written out below. class Class{ public: class(void) {this -> value = -1; } void setVal(int value) {this -> value = value;} int getVal(void) {return value;} private: int value; }; 5.3.9Image 1: This image shows an example of overloading constructor names, which has written out below in C++. class Class{ public: class(void) {this -> value = -1; } class(int val) setVal(int value) {this -> value = val;} void setVal(int value) {this -> value = value;} int getVal(void) {return value;} private: int value; }; 5.3.10Image 1: This image shows another example of overloading constructor names in C++, which is written out below. class Class{ public: class(int val) {this -> value = val; } void setVal(int value) {this -> value = value;} int getVal(void) {return value;} private: int value; }; 5.3.11Image 1: This image shows an example of copying constructors in C++. This has been written out below. #include <iostream> using namespace std; class Class1{ public: Class1(int val) {this -> value = val;} Class1(Class1 const &source) {value = source.value + 100;) int value; }; class Class2{ public: Class2(int val) {this -> value = val;} int value; }; int main(void) { Class1 object11(100), object12 = object11; Class2 object21(200), object22 = object21; cout<<object12.value<<endl; cout<<object22.value<<endl; return 0; } 5.3.12Image 1: This image shows an example of memory leaks in C++, which has been written out below. #include <iostream> using namespace std; class Class{ public: Class(int val){ value = new int[val]; cout<<”Allocation (“<< val << “) done.”<<endl; } int *value; }; void MakeALeak(void) { Class object(1000); } int main(void) { MakeALeak(); return 0; } 5.3.13Image 1: Shows an example of Destructors in C++, which has been written out below. #include <iostream> using namespace std; class Class{ public: Class(int val) { value = new int[val]; cout<<”Allocation (“<< val << “) done.”<<endl; } ~Class(void){ delete [] value; cout<<”Deletion done.”<<endl; } int *value; }; Void MakeALeak(void) { Class object(1000); } int main(void) { MakeALeak(); return 0; } |