Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is the the first part coded : ( please give a full answer to the question ) #include #include / / Global enum for

This is the the first part coded : (please give a full answer to the question)
#include
#include
// Global enum for the type of initialization
enum initTypeList { Random =1, Checkerboard, AllWhite };
// Function to read input from the file
int readInput(const char *filename, int *numRows, int *numCols, int *numRobots, int *initTypeValue, unsigned int *initSeed, int *numTurns, int *interval, char *outputFilename){
FILE *file = fopen(filename,"r");
int numScanned = fscanf(file,"%d %d %d %d %u %d %d %s", numRows, numCols, numRobots, initTypeValue, initSeed, numTurns, interval, outputFilename);
fclose(file);
if (numScanned !=8){
fprintf(stderr, "ERROR: Input file not opened correctly.
");
return 0;
}
if (*numRows 20||*numRows >300){
fprintf(stderr, "ERROR: The number of rows was outside the specified range (20 to 300 inclusive).
");
return 0;
}
if (*numCols 20||*numCols >300){
fprintf(stderr, "ERROR: The number of columns was outside the specified range (20 to 300 inclusive).
");
return 0;
}
if (*numRobots 1||*numRobots >10){
fprintf(stderr, "ERROR: The number of robots was outside the specified range (1 to 10 inclusive).
");
return 0;
}
if (*initTypeValue 1||*initTypeValue >3){
fprintf(stderr, "ERROR: The initTypeValue was outside the specified range (1 to 3 inclusive).
");
return 0;
}
if (*initSeed 10||*initSeed >32767){
fprintf(stderr, "ERROR: The initSeed was outside the specified range (10 to 32767 inclusive).
");
return 0;
}
if (*numTurns 10||*numTurns >5000){
fprintf(stderr, "ERROR: The number of turns was outside the specified range (10 to 5000 inclusive).
");
return 0;
}
if (*interval 1||*interval >*numTurns){
fprintf(stderr, "ERROR: The printing interval was outside the specified range (1 to number of turns inclusive).
");
return 0;
}
return 1;
}
int main(){
char filename[100];
printf("Enter the name of the input file: ");
scanf("%s", filename);
int numRows, numCols, numRobots, initTypeValue, numTurns, interval;
unsigned int initSeed;
char outputFilename[100];
int attempts =0;
while (!readInput(filename, &numRows, &numCols, &numRobots, &initTypeValue, &initSeed, &numTurns, &interval, outputFilename)){
attempts++;
if (attempts >=5){
fprintf(stderr, "ERROR: Failed to open the input file 5 times. Terminating the program.
");
return 1;
}
printf("Enter the name of the input file: ");
scanf("%s", filename);
}
printf("Input read successfully!
");
printf("Number of Rows: %d
Number of Columns: %d
Number of Robots: %d
Initialization Type: %d
Seed: %u
Number of Turns: %d
Printing Interval: %d
Output Filename: %s
",
numRows, numCols, numRobots, initTypeValue, initSeed, numTurns, interval, outputFilename);
return 0;
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

6. Identify seven types of hidden histories.

Answered: 1 week ago

Question

What is the relationship between humans and nature?

Answered: 1 week ago