Explanation:
This program will give us the random genarated values in the out put. Please find the attached out put screen shot for one of the random generated out put pattern.
Program:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define ROWSOBJ 10
#define COLSOBJ 10
int main (void) {
int iObj, jObj, kObj, directionObj;
char boardObj[ROWSOBJ][COLSOBJ];
const char lettersObj[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', 'Z'};
srand ((unsigned) time(NULL));
for (iObj = 0; iObj < ROWSOBJ; iObj++)
for (jObj = 0; jObj < COLSOBJ; jObj++)
boardObj[iObj][jObj] = '.';
iObj = 0;
jObj = 0;
kObj = 1;
boardObj[iObj][jObj] = lettersObj[0];
while (kObj < 26) {
directionObj = rand() % 4;
switch (directionObj) {
case 0: if (boardObj[iObj][jObj + 1] == '.' && jObj !=
ROWSOBJ - 1){
boardObj[iObj][jObj +1] = lettersObj[kObj];
kObj++; jObj++;}
if (boardObj[iObj][jObj + 1] != '.' && boardObj[iObj +
1][jObj] != '.' && boardObj[iObj - 1][jObj] != '.'
&& boardObj[iObj][jObj - 1] != '.')
kObj = 27;
break;
case 1: if (boardObj[iObj + 1][jObj] == '.' && iObj !=
COLSOBJ -1) {
boardObj[iObj + 1][jObj] = lettersObj[kObj];
kObj++; iObj++; }
if (boardObj[iObj][jObj + 1] != '.' && boardObj[iObj +
1][jObj] != '.' && boardObj[iObj - 1][jObj] != '.'
&& boardObj[iObj][jObj - 1] != '.')
kObj = 27;
break;
case 2: if (boardObj[iObj - 1][jObj] == '.' && iObj !=
0){
boardObj[iObj - 1][jObj] = lettersObj[kObj];
kObj++; iObj--; }
if (boardObj[iObj][jObj + 1] != '.' && boardObj[iObj +
1][jObj] != '.' && boardObj[iObj - 1][jObj] != '.'
&& boardObj[iObj][jObj - 1] != '.')
kObj = 27;
break;
case 3: if (boardObj[iObj][jObj - 1] == '.' && jObj != 0)
{
boardObj[iObj][jObj - 1] = lettersObj[kObj];
kObj++; jObj--;}
if (boardObj[iObj][jObj + 1] != '.' && boardObj[iObj +
1][jObj] != '.' && boardObj[iObj - 1][jObj] != '.'
&& boardObj[iObj][jObj - 1] != '.')
kObj = 27;
break;
}
}
for (iObj = 0; iObj < ROWSOBJ; iObj++) {
for (jObj = 0; jObj < COLSOBJ; jObj++)
printf ("%4c", boardObj[iObj][jObj]);
printf ("\n");
}
return 0;
}
Output screenshot:
C Programming. Write a prograrm that generates a "random walk" across a 10 × 10 array....
C++ Write a program that generates and prints 24 random values using an array and the rand () function. Implement an algorithm to find the maximum and a minimum number of random numbers generated. Use the header "#include <ctime>", "#include <cstdlib>" in addition to the usual header: "#include <iostream>"
Write a java program that generates 10 random lowercase letters (range from ‘a’ – ‘z’) and stores the characters in an array. Call a method that replaces all repetitions of a character with asterisk character ‘*’. Use JOptionPane to show the content of the array in main method.
MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random words from a training set as explained in the lectures on graphs. Do not hard-code the training set! Read it from a file. A suggested format for the input file: 6 a e m r s t 10 ate eat mate meet rate seat stream tame team tear Here are some suggestions for constants, array declarations, and helper functions #include <iostream> #include <fstream> #include...
In C++ write a complete and correct x++ program that generates student email addresses and prints them to the screen based upon the data found in an input file, called students . txt. Each line of the space, followed by the student’s last name. Every email address is to be of the form [email protected]. In general, each username has four parts in this order: (i) the student; last name in lowercase letters; (ii) a number between 10- 99 generated at...
Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive integer numbers from 1 to 999 (lottery numbers) and takes a single input from the user and checks the input against the 15 lottery numbers. The user wins if her/his input matches one of the lottery numbers. Your implementation must have a level of modularity (using functions) Functions you need to implement: Define function initialize() that takes array lotterNumbers[] as a parameter and assigns...
I need Help PLZ. I can't solving this in C program Given is a C program count_primes.c, which is an array Generates 10000 six-digit random numbers and then determines the number of primes in that array. It also measures the time that elapses during the calculation and returns it to the console along with the number of primes it finds. (a) Rewrite the program so that N threads are used to count the primes in the array. Each thread is...
This is for C programming: You will be given files in the following format: n word1 word2 word3 word4 The first line of the file will be a single integer value n. The integer n will denote the number of words contained within the file. Use this number to initialize an array. Each word will then appear on the next n lines. You can assume that no word is longer than 30 characters. The game will use these words as...
I need a basic program in C to modify my program with the following instructions: Create a program in C that will: Add an option 4 to your menu for "Play Bingo" -read in a bingo call (e,g, B6, I17, G57, G65) -checks to see if the bingo call read in is valid (i.e., G65 is not valid) -marks all the boards that have the bingo call -checks to see if there is a winner, for our purposes winning means...
For a C program hangman game: Create the function int play_game [play_game ( Game *g )] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...
in c++ please program for this code #include <iostream> #include <fstream> #include <string> #include <cstring> // for string tokenizer and c-style string processing #include <algorithm> // max function #include <stdlib.h> #include <time.h> using namespace std; // Extend the code here as needed class BTNode{ private: int nodeid; int data; int levelNum; BTNode* leftChildPtr; BTNode* rightChildPtr; public: BTNode(){} void setNodeId(int id){ nodeid = id; } int getNodeId(){ return nodeid; } void setData(int d){ data = d; } int getData(){ return data;...