These are from 25 November.
// two-dimensional arrays
#include <iostream>
#include <cstdlib>
using namespace std;
const int ROWS = 6;
const int COLS = 7;
void print_board(char board[ROWS][COLS]);
int main()
{
srand(time(NULL)); // Initialize random
char board[ROWS][COLS];
// Initialize the board
for(int r = 0; r < ROWS; r++)
{
for(int c = 0; c < COLS; c++)
{
//cout << r << ", " << c << "\n";
board[r][c] = '.';
}
}
// PRint the board
print_board(board);
// Place random letters on the board
for(char letter = 'A'; letter <= 'Z'; letter++)
{
// Choose random location on the board
int r = rand() % ROWS;
int c = rand() % COLS;
while(board[r][c] != '.')
{
r = rand() % ROWS;
c = rand() % COLS;
}
board[r][c] = letter;
//cout << r << "," << c << "\n";
}
cout << "AFTER:\n";
print_board(board);
return 0;
}
void print_board(char board[ROWS][COLS])
{
for(int r = 0; r < ROWS; r++)
{
for(int c = 0; c < COLS; c++)
{
cout << board[r][c];
}
cout << "\n";
}
}
#include <iostream>
using namespace std;
const int NUM_LETTERS = 26;
int main()
{
string mesg =
"Hello WORLD, this IS A test Message.";
int tally[NUM_LETTERS] = { 0 };
for(int i = 0; i < mesg.length(); i++)
{
char c = mesg[i];
if(c >= 'A' && c <= 'Z') {
int j = c - 'A';
tally[j]++;
}
else if(c >= 'a' && c <= 'z') {
int j = c - 'a';
tally[j]++;
}
}
// print results
for(int i = 0; i < NUM_LETTERS; i++) {
char c = 'A' + i;
cout << c << ": " << tally[i] << "\n";
}
}
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int tally[13] = { 0 }; // Only need 2-12.
const int NUM_ROLLS = 10000;
for(int i = 0; i < NUM_ROLLS; i++)
{
int d1 = rand() % 6 + 1;
int d2 = rand() % 6 + 1;
int k = d1+d2;
tally[k]++;
}
for(int i = 2; i <= 12; i++)
{
if(i < 10) cout << " ";
cout << i << ": ";
for(int j = 0; j < tally[i]/40; j++)
{
cout << "=";
}
cout << "\n";
}
return 0;
}