g++ -c Photoshop.cpp g++ -c Picture.cpp g++ -o Photoshop Photoshop.o Picture.o
class Checkerboard {
protected:
vector<vector<char> > board;
bool playerTurn;
public:
void initializeCheckerboard();
void initializeCheckerboard(const Checkerboard &initialBoard);
void printBoard() const;
bool move(const string &move);
int winner() const;
};
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 10 | 20 | 30 | 10 | 20 | 30 | 10 | 20 |
for (i = originalSize-1; i >= 0; i--) {
v[i+3] = v[i];
}
| Linear Probing | Quadratic Probing | |
|---|---|---|
| 0 | 30 | |
| 1 | 12 | 12 |
| 2 | ||
| 3 | 58 | 58 |
| 4 | 48 | 48 |
| 5 | 25 | |
| 6 | 30 | |
| 7 | 25 | |
| 8 | 19 | 19 |
| 9 | 52 | 52 |
| 10 | 32 | 32 |
|
|
^ is bitwise exclusive or:
1001 0101
^ 1010 1100
---------
0011 1001 = 0x39
| is bitwise or
1001 0101
| 1010 1100
---------
1011 1101 = 0xBD
>> is the right shift operator:
1010 1100 >> 3 = 0001 0101 = 0x15
a: 10
b: 90
x: 0x1004
y: 0x1004
3.6 is a double input = 16 intermediate sum = 16 14.5 is a double input = -5 intermediate sum = 11 Oops-that was not a number! input was not a number exiting program with an error
int countAndSwap(vector<vector<string> > &names) {
int row, col;
int count = 0;
string saveName;
for (row = 0; row < names.size(); row++) {
for (col = 0; col < row; col++) {
if (names[row][col] == names[col][row])
count++;
else {
saveName = names[row][col];
names[row][col] = names[col][row];
names[col][row] = saveName;
}
}
}
return count;
}
int main(int argc, char *argv[]) {
ifstream inputfile;
string command;
vector<double> accumulator;
int i;
double num;
int index;
try {
if (argc != 2) {
throw (string) "usage: ./sum filename";
}
inputfile.open(argv[1]);
while (inputfile >> command) {
if (command == "ADD") {
inputfile >> index;
inputfile >> num;
if (index >= accumulator.size()) {
accumulator.resize(index+1, 0);
}
accumulator.at(index) += num;
}
else if (command == "PRINT") {
printf("Vector Contents\n");
for (i = 0; i < accumulator.size(); i++) {
if (accumulator.at(i) == 0)
printf("%3d: Empty\n", i);
else
printf("%3d: %6.2f\n", i, accumulator.at(i));
}
}
}
inputfile.close();
}
catch (const string &msg) {
printf("%s\n", msg.c_str());
}
}