SlideShare a Scribd company logo
1 of 14
Download to read offline
In C language please!!
Download "bingo struct.c" from the instructor’s website. This is a fully functioning program.
Make sure that it compiles and run and test it for a while. This program uses C structs to store
data. REWRITE this program so that it does not use structs. Instead, use a 2D array of 2D arrays,
(A 4D array actually) with the following value encoding shown below. I suggest you develop the
program by getting it to work with one bingo board first. You will have to change the way you
are passing the boards around, see the prototypes below. There are several nested loops, the
indexing ranges will change slightly, but the nesting order should not change. Mostly, you will
be changing the way you reference data elements, and a little bit of logic.
// use this global table of Bingo boards instead of structs
// Trow Tcol Brow Bcol
unsigned char Table[TROWS][TCOLS][6][5];
/*
Value Encoding:
1-50 numbers
Page 7 of 7
250 the ASCII dot, indicates that this number has been picked (not visible)
66 B
73 I
78 N
71 G
79 O
*/
// new prototypes for passing board array data
void initBoard(char B[6][5]);
void printBoard(char B[6][5]);
Struct Version of of the program(need to modify this to fit the description above)!!!!:
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "conio.h"
#include "time.h"
#pragma warning (disable:4996)
// a single bingo board
struct BingoBoard {
char letters[5]; // the letters
int nums[5][5]; // the numbers
int visflag[5][5]; // is this number visible
};
// a global 2D table of Bingo boards
#define TROWS 3
#define TCOLS 3
struct BingoBoard Table[TROWS][TCOLS]; // REMOVE THIS DATA
/* a global table of Bingo boards, another way to do it
******USE THIS FOR YOUR HOMEWORK*****
This is a 4D array of BYTES.
Can also be thought of as a 2D array OF 2D arrays.
Trow Tcol Brow Bcol
unsigned char Table[TROWS][TCOLS] [6] [5]; // USE THIS DATA
Value Encoding:
1-50 numbers
250 the ASCII dot, indicates that this number has been picked (not visible)
66 B
73 I
78 N
71 G
79 O
*/
/*
Initializes one bingo board
*/
void initBoard(struct BingoBoard * B)
// void initBoard(char B[6][5]) // the other way
{
int row;
int col;
B->letters[0] = 'B';
B->letters[1] = 'I';
B->letters[2] = 'N';
B->letters[3] = 'G';
B->letters[4] = 'O';
// fill with random numbers
for (row = 0; row < 5; row++)
{
for (col = 0; col < 5; col++)
{
B->nums[row][col] = (rand() % 50) + 1; // 1 to 50
B->visflag[row][col] = 1; // all visible
}
}
}
/*
Prints one board on the console
*/
void printBoard(struct BingoBoard B)
// void printBoard(char B[6][5]) // the other way
{
int Brow;
int Bcol;
// first print letters
for (Bcol = 0; Bcol < 5; Bcol++)
printf(" %c", B.letters[Bcol]);
printf(" ");
// print the numbers if they are visible,
// otherwise print a dot (ASCII 250)
for (Brow = 0; Brow < 5; Brow++)
{
for (Bcol = 0; Bcol < 5; Bcol++)
{
// print visible numbers only
if (B.visflag[Brow][Bcol])
printf("%3d", B.nums[Brow][Bcol]);
else
printf(" %c", 250);
}
printf(" ");
}
}
/*
Prints an NxN Table of Bingo boards to the console
*/
void printTable()
{
int Brow;
int Bcol;
int Trow;
int Tcol;
// for each table row
for (Trow = 0; Trow < TROWS; Trow++)
{
// first print letters for each board on this Trow
for (Tcol = 0; Tcol < TCOLS; Tcol++)
{
// print letters for one board
for (Bcol = 0; Bcol < 5; Bcol++)
printf(" %c", Table[Trow][Tcol].letters[Bcol]);
printf(" ");
}
printf(" ");
// end print letters for this Trow
// print numbers for each board on this Trow
for (Brow = 0; Brow < 5; Brow++) // Brow
{
for (Tcol = 0; Tcol < TCOLS; Tcol++) // Tcol
{
for (Bcol = 0; Bcol < 5; Bcol++) // Bcol
{
// print only the visible numbers
if (Table[Trow][Tcol].visflag[Brow][Bcol])
printf("%3d", Table[Trow][Tcol].nums[Brow][Bcol]);
else
printf(" %c", 250);
}
printf(" ");
}
printf(" ");
}
printf(" ");
// end print numbers for this Trow
} // next Trow
}
/*
Receives a bingo move and checks for these values on all the boards.
Then checks for bingo
Returns the number of times this value appears on the boards,
plus a bitflag to indicate bingo
*/
int play(char ch, int num)
{
int Brow;
int Bcol;
int Trow;
int Tcol;
int found = 0;
int bingo = 0;
int i;
// search every single number
for (Trow = 0; Trow < TROWS; Trow++) // Trow
{
for (Tcol = 0; Tcol < TCOLS; Tcol++) // Tcol
{
for (Brow = 0; Brow < 5; Brow++) // Brow
{
for (Bcol = 0; Bcol < 5; Bcol++) // Bcol
{
// look for a number match in this ch column
if (Table[Trow][Tcol].nums[Brow][Bcol] == num
&& Table[Trow][Tcol].letters[Bcol] == ch)
{
Table[Trow][Tcol].visflag[Brow][Bcol] = 0;
found++;
// check for BINGO (an entire column filled)
if (!bingo) // neglect previous bingo from some other board
{
bingo = 64; // assume bingo! (a power of 2 bitflag)
// for each Brow
for (i = 0; i < 5; i++)
if (Table[Trow][Tcol].visflag[i][Bcol] != 0)
bingo = 0; // alas, no bingo
}
}
}
}
}
}
return found + bingo; // can take out the bingo later
}
/*
Le main
*/
void main(void)
{
time_t t;
struct BingoBoard B1;
int Trow;
int Tcol;
char ch;
int num;
int found;
// seed generator
srand((unsigned)time(&t));
// initialize and print one board for testing
//initBoard(&B1);
//printBoard(B1);
// initialize the global table of boards
for (Trow = 0; Trow < TROWS; Trow++)
for (Tcol = 0; Tcol < TCOLS; Tcol++)
initBoard(&Table[Trow][Tcol]);
// array version needs this ugly typecast:
//initBoard((char (*)[5]) Table[Trow][Tcol]);
printTable();
// main game loop
do
{
// prompt user for next move
printf("DRAW! Example N5 (Q to quit): ");
// get move from user
ch = getche();
if (ch == 'Q')break; // terminate main loop
scanf("%d", &num);
// play this user move
found = play(ch, num);
printTable();
// check for Bingo
if (found >= 64)
{
printf("BINGO!!!! ");
found -= 64; // take out the bitflag
}
// print results
if (found)
printf("%d occurance of %c%d found. ", found, ch, num);
else
printf("%c%d not found. ", ch, num);
} while (1);
printf(" ");
} Hints: T here is a line in plavo with Table[Trowl[Tcol].nums[Brow[Bcol] that will change to:
Table[Trow[Tcol[Brow][Bcol] And another line in play0 with Table[Trow][Tcol].visflag[i[Bcol
0 Table[Trow][Tc01][i][Bcol1-250 that will change to: And a few other similar changes
elsewhere Sample Output: RCWindows system32cmd.exe occurance of N20 found. DRAW?
Example N5
Solution
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "conio.h"
#include "time.h"
#pragma warning (disable:4996)
// a single bingo board
//struct BingoBoard {
char letters[5]; // the letters
int nums[5][5]; // the numbers
int visflag[5][5]; // is this number visible
//};
// a global 2D table of Bingo boards
#define TROWS 3
#define TCOLS 3
//struct BingoBoard
int Table[TROWS][TCOLS]; // REMOVE THIS DATA
/* a global table of Bingo boards, another way to do it
******USE THIS FOR YOUR HOMEWORK*****
This is a 4D array of BYTES.
Can also be thought of as a 2D array OF 2D arrays.
Trow Tcol Brow Bcol
unsigned char Table[TROWS][TCOLS] [6] [5]; // USE THIS DATA
Value Encoding:
1-50 numbers
250 the ASCII dot, indicates that this number has been picked (not visible)
66 B
73 I
78 N
71 G
79 O
*/
/*
Initializes one bingo board
*/
//void initBoard(struct BingoBoard * B)
void initBoard(char B[6][5]) // the other way
{
int row;
int col;
B->letters[0] = 'B';
B->letters[1] = 'I';
B->letters[2] = 'N';
B->letters[3] = 'G';
B->letters[4] = 'O';
// fill with random numbers
for (row = 0; row < 5; row++)
{
for (col = 0; col < 5; col++)
{
B->nums[row][col] = (rand() % 50) + 1; // 1 to 50
B->visflag[row][col] = 1; // all visible
}
}
}
/*
Prints one board on the console
*/
//void printBoard(struct BingoBoard B)
void printBoard(char B[6][5]) // the other way
{
int Brow;
int Bcol;
// first print letters
for (Bcol = 0; Bcol < 5; Bcol++)
printf(" %c", B.letters[Bcol]);
printf(" ");
// print the numbers if they are visible,
// otherwise print a dot (ASCII 250)
for (Brow = 0; Brow < 5; Brow++)
{
for (Bcol = 0; Bcol < 5; Bcol++)
{
// print visible numbers only
if (B.visflag[Brow][Bcol])
printf("%3d", B.nums[Brow][Bcol]);
else
printf(" %c", 250);
}
printf(" ");
}
}
/*
Prints an NxN Table of Bingo boards to the console
*/
void printTable()
{
int Brow;
int Bcol;
int Trow;
int Tcol;
// for each table row
for (Trow = 0; Trow < TROWS; Trow++)
{
// first print letters for each board on this Trow
for (Tcol = 0; Tcol < TCOLS; Tcol++)
{
// print letters for one board
for (Bcol = 0; Bcol < 5; Bcol++)
printf(" %c", Table[Trow][Tcol].letters[Bcol]);
printf(" ");
}
printf(" ");
// end print letters for this Trow
// print numbers for each board on this Trow
for (Brow = 0; Brow < 5; Brow++) // Brow
{
for (Tcol = 0; Tcol < TCOLS; Tcol++) // Tcol
{
for (Bcol = 0; Bcol < 5; Bcol++) // Bcol
{
// print only the visible numbers
if (Table[Trow][Tcol].visflag[Brow][Bcol])
printf("%3d", Table[Trow][Tcol].nums[Brow][Bcol]);
else
printf(" %c", 250);
}
printf(" ");
}
printf(" ");
}
printf(" ");
// end print numbers for this Trow
} // next Trow
}
/*
Receives a bingo move and checks for these values on all the boards.
Then checks for bingo
Returns the number of times this value appears on the boards,
plus a bitflag to indicate bingo
*/
int play(char ch, int num)
{
int Brow;
int Bcol;
int Trow;
int Tcol;
int found = 0;
int bingo = 0;
int i;
// search every single number
for (Trow = 0; Trow < TROWS; Trow++) // Trow
{
for (Tcol = 0; Tcol < TCOLS; Tcol++) // Tcol
{
for (Brow = 0; Brow < 5; Brow++) // Brow
{
for (Bcol = 0; Bcol < 5; Bcol++) // Bcol
{
// look for a number match in this ch column
if (Table[Trow][Tcol].nums[Brow][Bcol] == num
&& Table[Trow][Tcol].letters[Bcol] == ch)
{
Table[Trow][Tcol].visflag[Brow][Bcol] = 0;
found++;
// check for BINGO (an entire column filled)
if (!bingo) // neglect previous bingo from some other board
{
bingo = 64; // assume bingo! (a power of 2 bitflag)
// for each Brow
for (i = 0; i < 5; i++)
if (Table[Trow][Tcol].visflag[i][Bcol] != 0)
bingo = 0; // alas, no bingo
}
}
}
}
}
}
return found + bingo; // can take out the bingo later
}
/*
Le main
*/
void main(void)
{
time_t t;
// struct BingoBoard B1;
int Trow;
int Tcol;
char ch;
int num;
int found;
// seed generator
srand((unsigned)time(&t));
// initialize and print one board for testing
//initBoard(&B1);
//printBoard(B1);
// initialize the global table of boards
for (Trow = 0; Trow < TROWS; Trow++)
for (Tcol = 0; Tcol < TCOLS; Tcol++)
initBoard(&Table[Trow][Tcol]);
// array version needs this ugly typecast:
// initBoard((char (*)[5]) Table[Trow][Tcol]);
printTable();
// main game loop
do
{
// prompt user for next move
printf("DRAW! Example N5 (Q to quit): ");
// get move from user
ch = getche();
if (ch == 'Q')break; // terminate main loop
scanf("%d", &num);
// play this user move
found = play(ch, num);
printTable();
// check for Bingo
if (found >= 64)
{
printf("BINGO!!!! ");
found -= 64; // take out the bitflag
}
// print results
if (found)
printf("%d occurance of %c%d found. ", found, ch, num);
else
printf("%c%d not found. ", ch, num);
} while (1);
printf(" ");
}

More Related Content

Similar to In C language please!!Download bingo struct.c from the instruc.pdf

Here is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdfHere is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdf
anithareadymade
 
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docxNewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
curwenmichaela
 
Can you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfCan you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdf
aksachdevahosymills
 
Codigo fuente
Codigo fuenteCodigo fuente
Codigo fuente
BlackD10
 

Similar to In C language please!!Download bingo struct.c from the instruc.pdf (9)

Code
CodeCode
Code
 
Here is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdfHere is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdf
 
Debug(1).ppt
Debug(1).pptDebug(1).ppt
Debug(1).ppt
 
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docxNewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
 
Can you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfCan you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdf
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 
Introduction to cpp (c++)
Introduction to cpp (c++)Introduction to cpp (c++)
Introduction to cpp (c++)
 
Ethereum virtual machine for Developers Part 1
Ethereum virtual machine for Developers Part 1Ethereum virtual machine for Developers Part 1
Ethereum virtual machine for Developers Part 1
 
Codigo fuente
Codigo fuenteCodigo fuente
Codigo fuente
 

More from arrowit1

Google the four Characteristics of the Climate at Whirlpool, and pos.pdf
Google the four Characteristics of the Climate at Whirlpool, and pos.pdfGoogle the four Characteristics of the Climate at Whirlpool, and pos.pdf
Google the four Characteristics of the Climate at Whirlpool, and pos.pdf
arrowit1
 
Exercise 1-7 Identifying accounting principles and assumptions LO C4 .pdf
Exercise 1-7 Identifying accounting principles and assumptions LO C4 .pdfExercise 1-7 Identifying accounting principles and assumptions LO C4 .pdf
Exercise 1-7 Identifying accounting principles and assumptions LO C4 .pdf
arrowit1
 
____ 1. Lymph nodules found in the ileum____ 2. Responsible for bi.pdf
____ 1. Lymph nodules found in the ileum____ 2. Responsible for bi.pdf____ 1. Lymph nodules found in the ileum____ 2. Responsible for bi.pdf
____ 1. Lymph nodules found in the ileum____ 2. Responsible for bi.pdf
arrowit1
 
SQL FILE FROM MOODLEUSE [master]GO Object Databa.pdf
SQL FILE FROM MOODLEUSE [master]GO Object Databa.pdfSQL FILE FROM MOODLEUSE [master]GO Object Databa.pdf
SQL FILE FROM MOODLEUSE [master]GO Object Databa.pdf
arrowit1
 
Reference Health Law and EthicsAnalyze the impact the affordable c.pdf
Reference Health Law and EthicsAnalyze the impact the affordable c.pdfReference Health Law and EthicsAnalyze the impact the affordable c.pdf
Reference Health Law and EthicsAnalyze the impact the affordable c.pdf
arrowit1
 

More from arrowit1 (20)

If the proportion of an African population that are susceptible to M.pdf
If the proportion of an African population that are susceptible to M.pdfIf the proportion of an African population that are susceptible to M.pdf
If the proportion of an African population that are susceptible to M.pdf
 
How have a rock that was formed at the same time as the Earth was fo.pdf
How have a rock that was formed at the same time as the Earth was fo.pdfHow have a rock that was formed at the same time as the Earth was fo.pdf
How have a rock that was formed at the same time as the Earth was fo.pdf
 
help me to find a research article on a topic related to plant bodie.pdf
help me to find a research article on a topic related to plant bodie.pdfhelp me to find a research article on a topic related to plant bodie.pdf
help me to find a research article on a topic related to plant bodie.pdf
 
Google the four Characteristics of the Climate at Whirlpool, and pos.pdf
Google the four Characteristics of the Climate at Whirlpool, and pos.pdfGoogle the four Characteristics of the Climate at Whirlpool, and pos.pdf
Google the four Characteristics of the Climate at Whirlpool, and pos.pdf
 
How do you describe your ethnicity Do you include your family’s cou.pdf
How do you describe your ethnicity Do you include your family’s cou.pdfHow do you describe your ethnicity Do you include your family’s cou.pdf
How do you describe your ethnicity Do you include your family’s cou.pdf
 
How are spores produced by seed plants different than those of Bryoph.pdf
How are spores produced by seed plants different than those of Bryoph.pdfHow are spores produced by seed plants different than those of Bryoph.pdf
How are spores produced by seed plants different than those of Bryoph.pdf
 
Find the vertex, focus, and directrix of the parabola. Graph the equ.pdf
Find the vertex, focus, and directrix of the parabola. Graph the equ.pdfFind the vertex, focus, and directrix of the parabola. Graph the equ.pdf
Find the vertex, focus, and directrix of the parabola. Graph the equ.pdf
 
Exercise 1-7 Identifying accounting principles and assumptions LO C4 .pdf
Exercise 1-7 Identifying accounting principles and assumptions LO C4 .pdfExercise 1-7 Identifying accounting principles and assumptions LO C4 .pdf
Exercise 1-7 Identifying accounting principles and assumptions LO C4 .pdf
 
A plant has a unique photosynthetic plagment. The leaves of this pl.pdf
A plant has a unique photosynthetic plagment. The leaves of this pl.pdfA plant has a unique photosynthetic plagment. The leaves of this pl.pdf
A plant has a unique photosynthetic plagment. The leaves of this pl.pdf
 
____ 1. Lymph nodules found in the ileum____ 2. Responsible for bi.pdf
____ 1. Lymph nodules found in the ileum____ 2. Responsible for bi.pdf____ 1. Lymph nodules found in the ileum____ 2. Responsible for bi.pdf
____ 1. Lymph nodules found in the ileum____ 2. Responsible for bi.pdf
 
Write the correct master horizon designation (e.g. A, E, etc.) for t.pdf
Write the correct master horizon designation (e.g. A, E, etc.) for t.pdfWrite the correct master horizon designation (e.g. A, E, etc.) for t.pdf
Write the correct master horizon designation (e.g. A, E, etc.) for t.pdf
 
SQL FILE FROM MOODLEUSE [master]GO Object Databa.pdf
SQL FILE FROM MOODLEUSE [master]GO Object Databa.pdfSQL FILE FROM MOODLEUSE [master]GO Object Databa.pdf
SQL FILE FROM MOODLEUSE [master]GO Object Databa.pdf
 
Which of the following statements most accurately reflects the effec.pdf
Which of the following statements most accurately reflects the effec.pdfWhich of the following statements most accurately reflects the effec.pdf
Which of the following statements most accurately reflects the effec.pdf
 
Which of the following is (are) a primary focus of public health inf.pdf
Which of the following is (are) a primary focus of public health inf.pdfWhich of the following is (are) a primary focus of public health inf.pdf
Which of the following is (are) a primary focus of public health inf.pdf
 
Which of the following is NOT an activity of descriptive epidemiology.pdf
Which of the following is NOT an activity of descriptive epidemiology.pdfWhich of the following is NOT an activity of descriptive epidemiology.pdf
Which of the following is NOT an activity of descriptive epidemiology.pdf
 
What is the view of General Billy Mitchell about ‘air power’Sol.pdf
What is the view of General Billy Mitchell about ‘air power’Sol.pdfWhat is the view of General Billy Mitchell about ‘air power’Sol.pdf
What is the view of General Billy Mitchell about ‘air power’Sol.pdf
 
what additional component associated with outer skin epithelium is n.pdf
what additional component associated with outer skin epithelium is n.pdfwhat additional component associated with outer skin epithelium is n.pdf
what additional component associated with outer skin epithelium is n.pdf
 
What is the effect of this function below, assuming that a is an .pdf
What is the effect of this function below, assuming that a is an .pdfWhat is the effect of this function below, assuming that a is an .pdf
What is the effect of this function below, assuming that a is an .pdf
 
unix classesTask 3 (20 points)Write a bash program sort.sh to so.pdf
unix classesTask 3 (20 points)Write a bash program sort.sh to so.pdfunix classesTask 3 (20 points)Write a bash program sort.sh to so.pdf
unix classesTask 3 (20 points)Write a bash program sort.sh to so.pdf
 
Reference Health Law and EthicsAnalyze the impact the affordable c.pdf
Reference Health Law and EthicsAnalyze the impact the affordable c.pdfReference Health Law and EthicsAnalyze the impact the affordable c.pdf
Reference Health Law and EthicsAnalyze the impact the affordable c.pdf
 

Recently uploaded

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 

Recently uploaded (20)

FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 

In C language please!!Download bingo struct.c from the instruc.pdf

  • 1. In C language please!! Download "bingo struct.c" from the instructor’s website. This is a fully functioning program. Make sure that it compiles and run and test it for a while. This program uses C structs to store data. REWRITE this program so that it does not use structs. Instead, use a 2D array of 2D arrays, (A 4D array actually) with the following value encoding shown below. I suggest you develop the program by getting it to work with one bingo board first. You will have to change the way you are passing the boards around, see the prototypes below. There are several nested loops, the indexing ranges will change slightly, but the nesting order should not change. Mostly, you will be changing the way you reference data elements, and a little bit of logic. // use this global table of Bingo boards instead of structs // Trow Tcol Brow Bcol unsigned char Table[TROWS][TCOLS][6][5]; /* Value Encoding: 1-50 numbers Page 7 of 7 250 the ASCII dot, indicates that this number has been picked (not visible) 66 B 73 I 78 N 71 G 79 O */ // new prototypes for passing board array data void initBoard(char B[6][5]); void printBoard(char B[6][5]); Struct Version of of the program(need to modify this to fit the description above)!!!!: #include "stdio.h" #include "stdlib.h" #include "string.h" #include "conio.h" #include "time.h" #pragma warning (disable:4996) // a single bingo board struct BingoBoard {
  • 2. char letters[5]; // the letters int nums[5][5]; // the numbers int visflag[5][5]; // is this number visible }; // a global 2D table of Bingo boards #define TROWS 3 #define TCOLS 3 struct BingoBoard Table[TROWS][TCOLS]; // REMOVE THIS DATA /* a global table of Bingo boards, another way to do it ******USE THIS FOR YOUR HOMEWORK***** This is a 4D array of BYTES. Can also be thought of as a 2D array OF 2D arrays. Trow Tcol Brow Bcol unsigned char Table[TROWS][TCOLS] [6] [5]; // USE THIS DATA Value Encoding: 1-50 numbers 250 the ASCII dot, indicates that this number has been picked (not visible) 66 B 73 I 78 N 71 G 79 O */ /* Initializes one bingo board */ void initBoard(struct BingoBoard * B) // void initBoard(char B[6][5]) // the other way { int row; int col; B->letters[0] = 'B'; B->letters[1] = 'I'; B->letters[2] = 'N'; B->letters[3] = 'G';
  • 3. B->letters[4] = 'O'; // fill with random numbers for (row = 0; row < 5; row++) { for (col = 0; col < 5; col++) { B->nums[row][col] = (rand() % 50) + 1; // 1 to 50 B->visflag[row][col] = 1; // all visible } } } /* Prints one board on the console */ void printBoard(struct BingoBoard B) // void printBoard(char B[6][5]) // the other way { int Brow; int Bcol; // first print letters for (Bcol = 0; Bcol < 5; Bcol++) printf(" %c", B.letters[Bcol]); printf(" "); // print the numbers if they are visible, // otherwise print a dot (ASCII 250) for (Brow = 0; Brow < 5; Brow++) { for (Bcol = 0; Bcol < 5; Bcol++) { // print visible numbers only if (B.visflag[Brow][Bcol]) printf("%3d", B.nums[Brow][Bcol]); else printf(" %c", 250); }
  • 4. printf(" "); } } /* Prints an NxN Table of Bingo boards to the console */ void printTable() { int Brow; int Bcol; int Trow; int Tcol; // for each table row for (Trow = 0; Trow < TROWS; Trow++) { // first print letters for each board on this Trow for (Tcol = 0; Tcol < TCOLS; Tcol++) { // print letters for one board for (Bcol = 0; Bcol < 5; Bcol++) printf(" %c", Table[Trow][Tcol].letters[Bcol]); printf(" "); } printf(" "); // end print letters for this Trow // print numbers for each board on this Trow for (Brow = 0; Brow < 5; Brow++) // Brow { for (Tcol = 0; Tcol < TCOLS; Tcol++) // Tcol { for (Bcol = 0; Bcol < 5; Bcol++) // Bcol { // print only the visible numbers if (Table[Trow][Tcol].visflag[Brow][Bcol]) printf("%3d", Table[Trow][Tcol].nums[Brow][Bcol]);
  • 5. else printf(" %c", 250); } printf(" "); } printf(" "); } printf(" "); // end print numbers for this Trow } // next Trow } /* Receives a bingo move and checks for these values on all the boards. Then checks for bingo Returns the number of times this value appears on the boards, plus a bitflag to indicate bingo */ int play(char ch, int num) { int Brow; int Bcol; int Trow; int Tcol; int found = 0; int bingo = 0; int i; // search every single number for (Trow = 0; Trow < TROWS; Trow++) // Trow { for (Tcol = 0; Tcol < TCOLS; Tcol++) // Tcol { for (Brow = 0; Brow < 5; Brow++) // Brow { for (Bcol = 0; Bcol < 5; Bcol++) // Bcol { // look for a number match in this ch column
  • 6. if (Table[Trow][Tcol].nums[Brow][Bcol] == num && Table[Trow][Tcol].letters[Bcol] == ch) { Table[Trow][Tcol].visflag[Brow][Bcol] = 0; found++; // check for BINGO (an entire column filled) if (!bingo) // neglect previous bingo from some other board { bingo = 64; // assume bingo! (a power of 2 bitflag) // for each Brow for (i = 0; i < 5; i++) if (Table[Trow][Tcol].visflag[i][Bcol] != 0) bingo = 0; // alas, no bingo } } } } } } return found + bingo; // can take out the bingo later } /* Le main */ void main(void) { time_t t; struct BingoBoard B1; int Trow; int Tcol; char ch; int num; int found; // seed generator srand((unsigned)time(&t)); // initialize and print one board for testing
  • 7. //initBoard(&B1); //printBoard(B1); // initialize the global table of boards for (Trow = 0; Trow < TROWS; Trow++) for (Tcol = 0; Tcol < TCOLS; Tcol++) initBoard(&Table[Trow][Tcol]); // array version needs this ugly typecast: //initBoard((char (*)[5]) Table[Trow][Tcol]); printTable(); // main game loop do { // prompt user for next move printf("DRAW! Example N5 (Q to quit): "); // get move from user ch = getche(); if (ch == 'Q')break; // terminate main loop scanf("%d", &num); // play this user move found = play(ch, num); printTable(); // check for Bingo if (found >= 64) { printf("BINGO!!!! "); found -= 64; // take out the bitflag } // print results if (found) printf("%d occurance of %c%d found. ", found, ch, num); else printf("%c%d not found. ", ch, num); } while (1); printf(" "); } Hints: T here is a line in plavo with Table[Trowl[Tcol].nums[Brow[Bcol] that will change to: Table[Trow[Tcol[Brow][Bcol] And another line in play0 with Table[Trow][Tcol].visflag[i[Bcol
  • 8. 0 Table[Trow][Tc01][i][Bcol1-250 that will change to: And a few other similar changes elsewhere Sample Output: RCWindows system32cmd.exe occurance of N20 found. DRAW? Example N5 Solution #include "stdio.h" #include "stdlib.h" #include "string.h" #include "conio.h" #include "time.h" #pragma warning (disable:4996) // a single bingo board //struct BingoBoard { char letters[5]; // the letters int nums[5][5]; // the numbers int visflag[5][5]; // is this number visible //}; // a global 2D table of Bingo boards #define TROWS 3 #define TCOLS 3 //struct BingoBoard int Table[TROWS][TCOLS]; // REMOVE THIS DATA /* a global table of Bingo boards, another way to do it ******USE THIS FOR YOUR HOMEWORK***** This is a 4D array of BYTES. Can also be thought of as a 2D array OF 2D arrays. Trow Tcol Brow Bcol unsigned char Table[TROWS][TCOLS] [6] [5]; // USE THIS DATA Value Encoding: 1-50 numbers 250 the ASCII dot, indicates that this number has been picked (not visible) 66 B 73 I 78 N 71 G
  • 9. 79 O */ /* Initializes one bingo board */ //void initBoard(struct BingoBoard * B) void initBoard(char B[6][5]) // the other way { int row; int col; B->letters[0] = 'B'; B->letters[1] = 'I'; B->letters[2] = 'N'; B->letters[3] = 'G'; B->letters[4] = 'O'; // fill with random numbers for (row = 0; row < 5; row++) { for (col = 0; col < 5; col++) { B->nums[row][col] = (rand() % 50) + 1; // 1 to 50 B->visflag[row][col] = 1; // all visible } } } /* Prints one board on the console */ //void printBoard(struct BingoBoard B) void printBoard(char B[6][5]) // the other way { int Brow; int Bcol; // first print letters for (Bcol = 0; Bcol < 5; Bcol++) printf(" %c", B.letters[Bcol]);
  • 10. printf(" "); // print the numbers if they are visible, // otherwise print a dot (ASCII 250) for (Brow = 0; Brow < 5; Brow++) { for (Bcol = 0; Bcol < 5; Bcol++) { // print visible numbers only if (B.visflag[Brow][Bcol]) printf("%3d", B.nums[Brow][Bcol]); else printf(" %c", 250); } printf(" "); } } /* Prints an NxN Table of Bingo boards to the console */ void printTable() { int Brow; int Bcol; int Trow; int Tcol; // for each table row for (Trow = 0; Trow < TROWS; Trow++) { // first print letters for each board on this Trow for (Tcol = 0; Tcol < TCOLS; Tcol++) { // print letters for one board for (Bcol = 0; Bcol < 5; Bcol++) printf(" %c", Table[Trow][Tcol].letters[Bcol]); printf(" "); }
  • 11. printf(" "); // end print letters for this Trow // print numbers for each board on this Trow for (Brow = 0; Brow < 5; Brow++) // Brow { for (Tcol = 0; Tcol < TCOLS; Tcol++) // Tcol { for (Bcol = 0; Bcol < 5; Bcol++) // Bcol { // print only the visible numbers if (Table[Trow][Tcol].visflag[Brow][Bcol]) printf("%3d", Table[Trow][Tcol].nums[Brow][Bcol]); else printf(" %c", 250); } printf(" "); } printf(" "); } printf(" "); // end print numbers for this Trow } // next Trow } /* Receives a bingo move and checks for these values on all the boards. Then checks for bingo Returns the number of times this value appears on the boards, plus a bitflag to indicate bingo */ int play(char ch, int num) { int Brow; int Bcol; int Trow; int Tcol; int found = 0;
  • 12. int bingo = 0; int i; // search every single number for (Trow = 0; Trow < TROWS; Trow++) // Trow { for (Tcol = 0; Tcol < TCOLS; Tcol++) // Tcol { for (Brow = 0; Brow < 5; Brow++) // Brow { for (Bcol = 0; Bcol < 5; Bcol++) // Bcol { // look for a number match in this ch column if (Table[Trow][Tcol].nums[Brow][Bcol] == num && Table[Trow][Tcol].letters[Bcol] == ch) { Table[Trow][Tcol].visflag[Brow][Bcol] = 0; found++; // check for BINGO (an entire column filled) if (!bingo) // neglect previous bingo from some other board { bingo = 64; // assume bingo! (a power of 2 bitflag) // for each Brow for (i = 0; i < 5; i++) if (Table[Trow][Tcol].visflag[i][Bcol] != 0) bingo = 0; // alas, no bingo } } } } } } return found + bingo; // can take out the bingo later } /* Le main */
  • 13. void main(void) { time_t t; // struct BingoBoard B1; int Trow; int Tcol; char ch; int num; int found; // seed generator srand((unsigned)time(&t)); // initialize and print one board for testing //initBoard(&B1); //printBoard(B1); // initialize the global table of boards for (Trow = 0; Trow < TROWS; Trow++) for (Tcol = 0; Tcol < TCOLS; Tcol++) initBoard(&Table[Trow][Tcol]); // array version needs this ugly typecast: // initBoard((char (*)[5]) Table[Trow][Tcol]); printTable(); // main game loop do { // prompt user for next move printf("DRAW! Example N5 (Q to quit): "); // get move from user ch = getche(); if (ch == 'Q')break; // terminate main loop scanf("%d", &num); // play this user move found = play(ch, num); printTable(); // check for Bingo if (found >= 64) {
  • 14. printf("BINGO!!!! "); found -= 64; // take out the bitflag } // print results if (found) printf("%d occurance of %c%d found. ", found, ch, num); else printf("%c%d not found. ", ch, num); } while (1); printf(" "); }