ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 11 May 2017 My Price 8.00

implement the logic of conway game

Need help with C program. I have implement the logic of conway game of life but have problem with reading the input files on the command line.  Check the attachment. I have also attach the input file.  First line contain number of rows and columns for the 2-D matrix. 

 

#include <stdio.h>#define HEIGHT 25#define WIDTH 25#define LIFE_YES 1#define LIFE_NO 0// make the rest of the function calls easier to readtypedef int TableType[HEIGHT][WIDTH];void printTable(TableType table) {int height, width;for (height = 0; height < HEIGHT; height++) {for (width = 0; width < WIDTH; width++) {if (table[height][width] == LIFE_YES) {printf("X");} else {printf("-");}}printf("\n");}printf("\n");}// you already have a printTable, no need for this// clear was a better namevoid clearTable(TableType table) {int height, width;for (height = 0; height < HEIGHT; height++) {for (width = 0; width < WIDTH; width++) {table[height][width] = LIFE_NO;}}}void askUser(TableType tableA) {int i;int n;int height, width;printf("Enter the amount of initial organisms: ");scanf("%d", &n);for (i = 0; i < n; i++) {printf("Enter dimensions (x y) where organism %d will live: ", i +1);scanf("%d %d", &height, &width);tableA[height][width] = LIFE_YES;}printTable(tableA);printf("Generation 0");}int getNeighborValue(TableType table, int row, int col) {if (row < 0 || row >= HEIGHT|| col < 0 || col >= WIDTH|| table[row][col] != LIFE_YES ){return 0;} else {return 1;

Attachments:

Answers

(11)
Status NEW Posted 11 May 2017 06:05 AM My Price 8.00

-----------

Not Rated(0)