Recent Changes - Search:

Welcome to CAVI, the Cisco Academy for the Vision Impaired.

Course Fees Linux Wiki HTML Wiki Documentation Index PmWiki FAQ

Edit SideBar

Chapter8

8.1.1

Image 1:

This image shows the different types of operators that are available in C++. The operators are written out below.

Single symbols, symbols, di-graphs, tri-graphs, binary, ternary, infix, prefix, unary, operator and postfix.

8.1.2

Image 1:

This image shows another example of the different types of operators that are available in C++. These are written out below.

Single symbols, symbols, di-graphs, tri-graphs, binary, ternary, infix, prefix, unary, operator and postfix.

8.1.3

Image 1:

This image shows an example of overloaded operators for the push and pop functions in C++. The code is written out below.

Stack stack(100);
int var;

stack << 200; // push
stack >> var; // pop

8.1.4

Image 1:

This image shows an example of the << operator for the push function. The code is written out below.

void operator<< (int v) throw(stack_overflow);

8.1.5

Image 1:

This image shows the definition of the << operator for the push function in 8.1.4. The code is written out below.

void Stack::operator<< (int v) throw(stack_overflow) {
	push(v);
}

8.1.6

Image 1:

This image shows a new function for main with the << operator included. The code is written out below.

#include “mystack_01.h”
#include<iostream>

using namespace std;

int main(void) {
	int i = 2;
	Stack stk;

	stk << 1;
	stk << 2 * i;
 	stk << i;
	cout << stk.pop() << endl;
	cout << stk.pop() << endl;
	cout << stk.pop() << endl;
	return 0;
}

8.1.7

Image 1:

This image shows the >> operator for the pop member function. The code is written out below.

void operator>> (int &v) throw(stack_empty);

8.1.8

Image 1:

This image shows the >> operator and the pop member function implementation. The code is written out below.

void Stack::operator>> (int &v) throw(stack_empty) {
	v = pop();
}

8.1.9

Image 1:

This image shows another example of the >> operator in the modified main function. The code is written out below.

#include “mystack_02.h”
#include<iostream>

using namespace std;

int main(void) {
	int i = 2; 
	Stack stk;
	stk << 1;
	stk << 2 * i;
	stk << i;
 	stk >> i; cout << i << endl;
	stk >> i; cout << i << endl;
stk >> i; cout << i << endl;

	return 0;
}

8.1.10

Image 1:

This image shows the stream operator for the << operator. The code is written out below.

Stack& operator<< (int v) throw(stack_overflow);

8.1.11

Image 1:

This image shows the improved definition for the << operator. The code is written out below.

Stack& Stack::operator<< (int v) throw (stack_overflow) {
	Push(v);
	return *this
}

8.1.12

Image 1:

This image shows a modified main function with the << operator included. The code is written out below.

#include<iostream>

using namespace std;

int main(void) {
	int i = 2
	Stack stk;
	stk << 1 << 2 * i;
	stk >> i; cout << i << endl;
	stk >> i; cout << i << endl;
	return 0;
}

8.1.13

Image 1:

This image shows the improved >> operator. The code is written out below.

Stack& operator>> (int &v) throw(stack_empty);

8.1.14

Image 1:

This image shows the improved definition for the >> operator. The code is written out below.

Stack& Stack::operator>> (int &v) throw(stack_empty) {
	v = pop();
	return *this;
}

8.1.15

Image 1:

This image shows the new function for main with the >> operator written out below.

#include “mystack_04.h”
#include<iostream>

using namespace std;

int main(void) {
	int i = 2, j;
	Stack stk;
	stk << 1 << 2 * i;
 	stk >> j >> i;
	cout << j << endl << i << endl;
	return 0;
}

8.1.16

Image 1:

This image shows a new function for main with overloaded operators. The code is written out below.

#include “mystack.h”
#include<iostream>

using namespace std;

Stack& operator<< (Stack &s, int v) throw(stack_overflow) {
	s.push(v);
	return s;
}

Stack& operator>> (Stack &s, int &v) throw(stack_empty) {
	v = s.pop();
	return s;
};

int main(void) {
	int i = 2, j;
	Stack stk;
	stk << 1 << 2 * i;
 	stk >> j >> i;
	cout << j << endl << i << endl;
	retun 0;
}

8.1.17

Image 1:

This image shows an indexing operator for the stack. The code is written out below.

int& operator[] (int index) throw(std::range_error);

8.1.18

Image 1:

This image shows the indexing operator definition. The code is written out below.

int& Stack::operator[] (int index) throw(std::range_error) {
	if(index > 0 || index <= -SP)
		throw std::range_error(“out of stack”);
	return stackstore[SP + index – 1];
}

8.1.19

Image 1:

This image shows a new function for main with indexing operators included. The code is written out below.

#include “mystack_06.h”
#include<iostream>

using namespace std;

int main(void) {
	int i = 2, j;
	Stack stk;
	stk << 1 << 2 * i;
	cout << stk[0] << endl << stk[-1] << endl;
	stk[0] = stk[-1] = 0;
	stk >> i >> j;
	cout << i << endl << j << endl;
	return 0;
}

8.2.1

Image 1:

This image shows the days of the week. The list is written out below.

Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.

Edit - History - Print - Recent Changes - Search
Page last modified on August 17, 2017, at 01:32 PM