Questions
Complete the project functions for this week. These functions are main_menu(), column_full() and get_move(). To complete...

Complete the project functions for this week. These functions are main_menu(), column_full() and get_move(). To complete these functions, first remove the library function call from the function in the template (main_menu_lib, etc), then replace that with your own code to complete the function. You can test your functions separate from the project by creating a small main() function that calls them (with appropriate inputs), or you can compile the entire project and see if it works.main_menu(): This function displays the main menu to the user, which should say "Welcome to the Connect 4 Game", and then prompt the user to ask if they would like to start a new game (press 'n'), load a game (press 'l') or quit (press 'q'). If the user selects new game, the main_menu function should return 1. If they select load game, it should return 2, and if they choose quit it should return -1. If any other input is entered, the user should be prompted to re-enter their choice until a valid input is chosen.column_full(): This function takes the entire board (a COLS x ROWS array of ints) as input as well as a single integer representing the column number to be checked. Note that this input is between 1 and COLS, not0 and COLS-1 so does not correspond exactly to the array dimension.Your function should then check if the specified column is full or not, and return 1 if full, 0 otherwise. The column is full if every element in the column is non-zero.get_move(): This function takes the entire board (a COLS x ROWS array of ints) as input, and then reads a column number from the user, checks that the supplied column is valid (between 1 and COLS), not full (using the column_full() function you've already written) and then returns the valid column number. If the input is invalid or the column is full, an appropriate error message should be displayed and the user asked to enter another column.

TEMPLATE FILE:

#include 
#include 
#include 
#include 
#include 
#include "connect4.h"

int main ( void ){

    int option ;
        Game g ;

        // intitialise random seed
        srand(time(NULL));

    while (( option = main_menu()) != -1 ){
        if ( option == 1 ){
            // setup a new game
            setup_game ( &g ) ;
            // now play this game
            play_game ( &g ) ;
        } else if ( option == 2 ){
            // attempt to load the game from the save file
            if ( load_game ( &g, "game.txt" ) == 0 ){
                // if the load went well, resume this game
                play_game ( &g ) ;
            } else {
                printf ( "Loading game failed.\n") ;
            }
        } else if ( option == -1 ){
            printf ( "Exiting game, goodbye!\n") ;
        }
    }
}

// WEEK 1 TASKS
// main_menu()
// column_full()
// get_move()

// displays the welcome screen and main menu of the game, and prompts the user to enter an option until
// a valid option is entered.
// Returns 1 for new game, 2 for load game, -1 for quit
int main_menu ( void ){

    // Dipslay Welcome message

    // Continue asking for an option until a valid option (n/l/q) is entered
    // if 'n', return 1
    // if 'l', return 2
    // if 'q', return -1
    // if anything else, give error message and ask again..

    return main_menu_lib () ;
}


// Returns TRUE if the specified column in the board is completely full
// FALSE otherwise
// col should be between 1 and COLS
int column_full ( int board[COLS][ROWS], int col ){

    // check the TOP spot in the specified column (remember column is between 1 and COLS, NOT 0 and COLS-1 so you'll need to modify slightly
    // if top spot isn't empty (0 is empty) then the column is full, return 1
    // otherwise, return 0
    return column_full_lib ( board, col ) ;
}


// prompts the user to enter a move, and checks that it is valid
// for the supplied board and board size
// Returns the column that the user has entered, once it is valid (1-COLS)
// note that this value is betweeen 1 and COLS (7), NOT between 0 and 6!!
// If the user enters 'S' or 's' the value -1 should be returned, indicating that the game should be saved
// If the user enters 'Q' or 'q' the value -2 should be returned, indicating that the game should be abandoned
int get_move ( int board[COLS][ROWS] ){

    // repeat until valid input is detected:

    // read a line of text from the user
    // check if the user has entered either 's' (return -1) or 'q' (return -2)
    // if not, read a single number from the inputted line of text using sscanf
    // if the column is valid and not full, return that column number
    // otherwise, give appropriate error message and loop again

    return get_move_lib ( board ) ;
}


// END OF WEEK 1 TASKS
#ifndef CONNECT4_H
#define CONNECT4_H 1

#define ROWS 6      // height of the board
#define COLS 7      // width of the board (values of 9 are going to display poorly!!)

// These lines detect what sort of compiler you are using. This is used to handle the time delay
// function wait() in various operating systems. Most OS will use sleep(), however for windows it is
// Sleep() instead.
#ifdef _WIN32
    #include <windows.h>
#else
    #include <unistd.h>
#endif

typedef struct {

    int player1, player2 ;      // variables for each player - 1 for human, 0 for computer player
    int board[COLS][ROWS] ;     // the game board. 0 for empty space, 1 for player 1, 2 for player 2
                                // Note that row 0 is the TOP row of the board, not the bottom!
                                // column 0 is on the left of the board
    int turn ;                  // whose turn it is, 1 or 2
    int winner ;                // who has won - 0 for nobody, 1 for player 1, 2 for player 2
} Game ;

// displays the welcome screen and main menu of the game, and prompts the user to enter an option until
// a valid option is entered.
// Returns 1 for new game, 2 for load game, -1 for quit
int main_menu ( void ) ;

// displays the board to the screen
int display_board ( int[COLS][ROWS] ) ;


// sets up the game to a new state
// prompts the user if each player should be a human or computer, and initialises the relevant fields
// of the game structure accordingly
int setup_game ( Game *g ) ;


// Returns TRUE if the specified column in the board is completely full
// FALSE otherwise
// col should be between 1 and COLS
int column_full ( int[COLS][ROWS], int col ) ;


// plays a game until it is over
int play_game ( Game *g ) ;


// prompts the user to enter a move, and checks that it is valid
// for the supplied board and board size
// Returns the column that the user has entered, once it is valid (1-COLS)
// note that this value is betweeen 1 and COLS (7), NOT between 0 and 6!!
// If the user enters 'S' or 's' the value -1 should be returned, indicating that the game should be saved
// If the user enters 'Q' or 'q' the value -2 should be returned, indicating that the game should be abandoned
int get_move ( int[COLS][ROWS] ) ;

// calcualtes a column for the computer to move to, using artificial "intelligence"
// The 'level' argument describes how good the computer is, with higher numbers indicating better play
// 0 indicates very stupid (random) play, 1 is a bit smarter, 2 smarter still, etc..
int computer_move ( int[COLS][ROWS], int colour, int level ) ;

// adds a token of the given value (1 or 2) to the board at the
// given column (col between 1 and COLS inclusive)
// Returns 0 if successful, -1 otherwise
int add_move ( int b[COLS][ROWS], int col, int colour ) ;

// determines who (if anybody) has won.  Returns the player id of the
// winner, otherwise 0
int winner ( int[COLS][ROWS] ) ;

// determines if the board is completely full or not
int board_full ( int[COLS][ROWS] ) ;


// saves the game to the specified file. The file is text, with the following format
// player1 player2 turn winner
// board matrix, each row on a separate line
// Example:
//
//1 0 1 0        player 1 human, player 2 computer, player 1's turn, nobody has won
//0 0 0 0 0 0 0  board state - 1 for player 1's moves, 2 for player 2's moves, 0 for empty squares
//0 0 0 0 0 0 0
//0 0 0 2 0 0 0
//0 0 0 2 0 0 0
//0 2 1 1 1 0 0
//0 2 2 1 1 2 1
int save_game ( Game g, char filename[] ) ;


// loads a saved game into the supplied Game structure. Returns 0 if successfully loaded, -1 otherwise.
int load_game ( Game *g, char filename[] ) ;


// waits for s seconds - platform specific! THIS FUNCTION IS INCLUDED IN THE LIBRARY, NO NEED TO WRITE IT!
void wait_seconds ( int s ) ;


// library versions of functions. Exactly the same behaviour done by course staff. Please just call these if you have not completed your version as yet.
int display_board_lib ( int[COLS][ROWS] ) ;
int setup_game_lib ( Game *g ) ;
int column_full_lib ( int[COLS][ROWS], int col ) ;
int play_game_lib ( Game *g ) ;
int get_move_lib ( int[COLS][ROWS] ) ;
int add_move_lib ( int b[COLS][ROWS], int col, int colour ) ;
int winner_lib ( int[COLS][ROWS] ) ;
int board_full_lib ( int[COLS][ROWS] ) ;
int computer_move_lib ( int[COLS][ROWS], int colour, int level ) ;
int save_game_lib ( Game g, char filename[] ) ;
int load_game_lib ( Game *g, char filename[] ) ;
int main_menu_lib ( void ) ;


#endif

In: Computer Science

Topic: Template template void arrayContents(const T *arr, int countSize); int main() { const int ACOUNT =...

Topic: Template
template
void arrayContents(const T *arr, int countSize);
int main()
{
const int ACOUNT = 5;
const int BCOUNT = 7;
const int CCOUNT = 6;
int a[ACOUNT] = {1, 2, 3, 4, 5};
double b[BCOUNT] = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7};
char c[CCOUNT] = "HELLO";
cout <<"Array A contents: \n";
arrayContents(a, ACOUNT);
cout <<"Array B contents: \n";
arrayContents(b, BCOUNT);
cout <<"Array C contents: \n";
arrayContents(c, CCOUNT);
return 0;
}
template
void arrayContents(const T *arr, int countSize)
{
for(int i = 0; i < countSize; i++)
cout << arr[i] << " ";
cout << endl;
}
Rewrite the above code and overload function template arrayContents(), so it will
takes two additional integer arguments, named int lowSubscript and int

highSubscript. The function shall validate the lowSubscript and
highSubscript; for:

 If both either is out of range, or
 If highSubscript is less than or equal to lowSubscript
hence,the overloaded arrayContents function should return 0. Otherwise, it
should return the number of elements printed.

Modify the main() function to exercise each versions of arrayContents on arrays
a, b and c.
Notes: the lowSubscript and highSubscript is to identify the index of array.

In: Computer Science

Identify the main components of an information system. What is a mission-critical system? software development

Identify the main components of an information system. What is a mission-critical system?

software development

In: Computer Science

Using C++ code, write a program to convert a distance d given in inches (in) to...

Using C++ code, write a program to convert a distance d given in inches (in) to centimeters (cm), where d is input by a user via the keyboard and 1in = 2.54cm. Your submission should include screenshots of the execution of the program using the values 1.5, 4 and 6.75.

In: Computer Science

5C++ Questions 1. What will the following code print? num = 8; cout << --num <<...

5C++ Questions

1. What will the following code print?
num = 8;
cout << --num << " ";
cout << num++ << " ";
cout << num;

2.Since the while loop evaluates the condition before executing the statement(s), it is known as a(n)____ loop, whereas the do-while loop evaluates the condition after the statements have been executed, it is known as a(n)____ loop.

3.T/F While loops can only be used when a counter is decremented to zero. If the counter is incremented you must use the do-while loop.

4.How many times will the following program print Hello?

counter = 3; 
while (counter > 0) {
    loop = 5;
    while (loop > 0) {
          cout << "Hello" << endl;
          loop--;
     }
     counter--;
}

5.If nothing within a while loop causes the condition to become false, a(n) ________ may occur.

6.The -- operator ... (check all that apply)

subtracts one from the value of its operand.

must have an lvalue, such as a variable, as its operand.

can be used in either prefix or postfix mode.

is a unary operator.

7.Which of the following statements will result in an infinite loop.

x = 10; 
while (x >= 0) {
    cout << x;
    ++x; 
}
x = 10; 
while (x >= 0) {
    cout << x;
}
x = 0; 
while (x <= 10) {
    cout << x;
    x = 10;
}
x = 10; 
while (x >= 0); {
    cout << x;
    x--;
}

8.T/F In C++, a file must be opened before the contents can be read.

9. T/F In C++, a file must exists before it can be written to.

10.Which of the following statements show the proper way to use the increment (++) operator.

x++ = 1023;

x = 23++;

y = ++x;

counter--;

In: Computer Science

Why and how is TCP /IP important to a IT specialist ?

Why and how is TCP /IP important to a IT specialist ?

In: Computer Science

<Haskell> Define an action adder :: IO () that reads a given number of integers from...

<Haskell>

Define an action adder :: IO () that reads a given number of integers from the keyboard, one per line, and displays their sum. For example: > adder

How many numbers? 5

1 3 5 7 9

The total is 25

Hint: start by defining an auxiliary function that takes the current total and how many numbers remain to be read as arguments. You will also likely need to use the library functions read and show.

In: Computer Science

import kotlinx.coroutines.* // TODO 1 fun sum(valueA: Int, valueB: Int): Int {     return 0 }...

import kotlinx.coroutines.*

// TODO 1
fun sum(valueA: Int, valueB: Int): Int {
    return 0
}

// TODO 2
fun multiple(valueA: Int, valueB: Int): Int {
    return 0
}

fun main() = runBlocking {

    println("Counting...")

    val resultSum = async { sum(10, 10) }
    val resultMultiple = async { multiple(20, 20) }

    // TODO 3
    println()
}

TODO 1:
Change it to suspend function with the following conditions:
Has a waiting time of 3 seconds before the next operation runs.
Returns the value of the sum of valueA and valueB.

TODO 2:
Change it to suspend function with the following conditions:
Has a waiting time of 2 seconds before the next operation runs.
Returns the value of the multiplication valueA and valueB.

TODO 3:
Add a function to print the deferred values of the resultSum and resultMultiple variables on the console.

If run, the console will display the text:
Counting ...
Result sum: 20
Multiple results: 400

In: Computer Science

list 3 pros and 3 cons for Virtual reality technology and Augmented Reality technology, then discuss...

list 3 pros and 3 cons for Virtual reality technology and Augmented Reality technology, then discuss how you think these technologies will take part in out future ?

In: Computer Science

**I need to make this program to make sure that the numbers are unique. In another...

**I need to make this program to make sure that the numbers are unique. In another word, if the number has been generated and appear early, it should continue to find the next number until the number is unique.

Hint: use the array to check whether the number has been generated.

#include <iostream>

#include <cstdlib>

#include <ctime>

using namespace std;

int main() {

srand(time(NULL));

int n, low, high;

cout << "Enter how many random numbers you would like to see: ";

cin >> n;

cout << "Enter the lower limit now: ";

cin >> low;

cout << "And now enter the higher limit: ";

cin >> high;

cout << n << " random numbers:";

for (int i = 0; i < n; ++i) {

cout << " " << low + (rand() % (high-low+1)) << endl;

}

cout << endl;

return 0;

}

Please show me how it can be done and explain code needed if possible. Thanks!

In: Computer Science

fun main() {     val stringResult = getResult("Kotlin")     val intResult = getResult(100)     // TODO...

fun main() {
    val stringResult = getResult("Kotlin")
    val intResult = getResult(100)

    // TODO 2
    println()
}

// TODO 1
fun <T> getResult(args: T): Int {
    return 0
}

TODO 1:
Create a new generics function with the following conditions:
The function name is getResult.
Has one type of parameter.
If the attached argument is of type Int, then the value returned is the value of the argument multiplied by 5.
If the attached argument is of type String, the value returned is a character length.
If the attached argument is of type other than Int and String, then the returned value is 0.

TODO 2:
Add functions to print the values of the stringResult and intResult variables in the console.

In: Computer Science

C++ How do I initialize a clock to 0 and run it constantly throughout the program?...

C++ How do I initialize a clock to 0 and run it constantly throughout the program? THEN, how do I get the time at that moment multiple times? As in id like to set the

clock = 0,

do stuff

do stuff

get time now, store it

do stuff

get time now, store it

then also be able to do arithmetic on it, for instance, last time - current time = 2 seconds. I made it sound complicated but I believe this is very easy.

In: Computer Science

Python code for Multivariable Unconstrained *unidirectional search*(topic:- optimization techniques)

Python code for Multivariable Unconstrained *unidirectional search*(topic:- optimization techniques)

In: Computer Science

python 2.7 Dash How to draw a bar & line & pie chart for below dict...

python 2.7 Dash

How to draw a bar & line & pie chart for below dict data by using Dash?

The value is the percentage of each month. So total will be 100.

{'Mar': 17.973851593144104, 'Feb': 10.540182187664472, 'Sep': 8.200076731097335, 'Apr': 12.080717324339435, 'Jan': 16.118724221364918, 'Nov': 12.29654875876966, 'Dec': 11.378407574427893, 'Oct': 11.411491609192186}

Please provide the python 2.7 code.

In: Computer Science

// TODO 1 class Cat(private val name: String) { var sleep: Boolean = false fun toSleep()...

// TODO 1

class Cat(private val name: String) {

var sleep: Boolean = false

fun toSleep() {

println()

}

}

fun main() {

// TODO 2

val gippy = Cat("")

gippy.toSleep()

gippy.sleep = true

gippy.toSleep()

}

TODO 1:

Complete the code in the Cat class with the following conditions:

Create a getter setter function for the sleep property in which there is a function to print text:

The getter / setter function is called

Add code to the toSleep () function to print text:

[name], sleep!

if sleep is true and text:

name, let's play!

if sleep is false.

TODO 2:

Complete initialization with Cat class.

If run the console will display text like the following:

The getter function is called

Gippy, let's play!

The setter function is called

The getter function i

In: Computer Science