Computer Science Cheat Sheet

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string input;
char asc1, asc2, asc;
int cols;
cout<<"Input any two ASCII characters from the keyboard"<<endl;
cout<<"Example: d and k and 3"<<endl<<endl;
getline(cin,input);
cout<<endl;
cout<<"input:"<<input<<endl<<endl;
asc1 = input[0];
asc2 = input[6];
cols = input[12]- 48;
cout<<asc1<<" "<<asc2<<" "<<cols<<endl<<endl;
asc = asc1;
while (asc != asc2+1)
{
for(int count = 0; count < cols; count++)
{
cout<<asc<<" ";
asc++;
if(asc==asc2+1)
count=1000;
}
cout<<endl<<endl;
}
system("PAUSE");
return 0;
}
#include <iostream.h>
#include <stdlib.h>
#include <iomanip.h>
int main()
{
char board[3][3];
int row, col;
cout<<"First move in TIC-TAC-TOE"<<endl<<endl;
for(row=0; row<3; row++)
{
for(col=0; col<3; col++)
board[row][col] = '_';
}
for(int row=0; row<3; row++)
{ cout<<setw(20);
for(int col=0; col<3; col++)
{
cout<<" "<<board[row][col];
}
cout<<endl<<endl;
}
cout<<endl<<endl;
cout<<"What row and column to place 'X' in?"<<endl;
cout<<"row: ";
cin>>row;
cout<<"col: ";
cin>>col;
system("CLS");
cout<<endl<<endl;
board[row-1][col-1] = 'X';
for(int row=0; row<3; row++)
{
cout<<setw(20);
for(int col=0; col<3; col++)
{
cout<<" "<<board[row][col];
}
cout<<endl<<endl;
}
cout<<endl<<endl;
cout<<endl<<endl;
system("PAUSE");
return 0;
}
#include <stdlib.h>
#include <iomanip.h>
int main()
{
char board[3][3];
int row, col;
cout<<"First move in TIC-TAC-TOE"<<endl<<endl;
for(row=0; row<3; row++)
{
for(col=0; col<3; col++)
board[row][col] = '_';
}
for(int row=0; row<3; row++)
{ cout<<setw(20);
for(int col=0; col<3; col++)
{
cout<<" "<<board[row][col];
}
cout<<endl<<endl;
}
cout<<endl<<endl;
cout<<"What row and column to place 'X' in?"<<endl;
cout<<"row: ";
cin>>row;
cout<<"col: ";
cin>>col;
system("CLS");
cout<<endl<<endl;
board[row-1][col-1] = 'X';
for(int row=0; row<3; row++)
{
cout<<setw(20);
for(int col=0; col<3; col++)
{
cout<<" "<<board[row][col];
}
cout<<endl<<endl;
}
cout<<endl<<endl;
cout<<endl<<endl;
system("PAUSE");
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
string message;
char choice;
do
{
cout<<" Message Manipulation Menu"<<endl;
cout<<" a) Add to the message"<<endl;
cout<<" b) Erase message and start all over"<<endl;
cout<<" c) Display current message"<<endl;
cout<<" q) Quit "<<endl<<endl<<"Choice:";
cin>>choice;
cin.ignore();
system("CLS");
switch(choice)
{
case 'a': { string new_message;
cout<<"Enter in message to add: ";
getline(cin,new_message);
message += " ";
message += new_message;break;}
case 'b': {message = " ";
cout<<"Message erased"<<endl<<endl; system("PAUSE");break;}
case 'c': {cout<<"Current message: "<<message<<endl<<endl;system("PAUSE");break;}
case 'q': {cout<<"GAME OVER"<<endl<<endl;system("PAUSE");
return 0;break;}
}
system("CLS");
}while(choice != 'q');
}
#include <string>
using namespace std;
int main()
{
string message;
char choice;
do
{
cout<<" Message Manipulation Menu"<<endl;
cout<<" a) Add to the message"<<endl;
cout<<" b) Erase message and start all over"<<endl;
cout<<" c) Display current message"<<endl;
cout<<" q) Quit "<<endl<<endl<<"Choice:";
cin>>choice;
cin.ignore();
system("CLS");
switch(choice)
{
case 'a': { string new_message;
cout<<"Enter in message to add: ";
getline(cin,new_message);
message += " ";
message += new_message;break;}
case 'b': {message = " ";
cout<<"Message erased"<<endl<<endl; system("PAUSE");break;}
case 'c': {cout<<"Current message: "<<message<<endl<<endl;system("PAUSE");break;}
case 'q': {cout<<"GAME OVER"<<endl<<endl;system("PAUSE");
return 0;break;}
}
system("CLS");
}while(choice != 'q');
}






are you sure this is ok.....