Question

In: Computer Science

in C++ You will overload a function named printArray. The function will assign values to each...

in C++

  1. You will overload a function named printArray. The function will assign values to each element and print out a single dimension array of integers and an array of characters. The main body of the program will call each function. (6 points)

  1. Using the player switch portion of the tic tac toe game, create a function that does the switch. This is a practice in applying local variables, parameters, and global variables. (4 points)

Solutions

Expert Solution

I have implemented the overloaded printArray() and mySwitch() per the given description


Please find the follwoing Code Screenshot,Output and Code.


ANY CLARIFICATIONS REQUIRED LEAVE A COMMENT


1.CODE SCREENSHOT


2.OUTPUT


3.CODE :

#include<iostream>
using namespace std;
//Overloaded printArray function which recive 
//an integer array and number of elements (len)
int printArray(int arr[],int len){
        cout<<"Elements in the Integer Array are   :\t";
        //print the elements of the array
        for(int i=0;i<len;i++)
                cout<<arr[i]<<"\t";
        cout<<endl;
}
//Overloaded printArray function which recive 
//an character array and number of elements (len)
int printArray(char arr[],int len){
        cout<<"Elements in the Character Array are :\t";
        //print the elements of the array
        for(int i=0;i<len;i++)
                cout<<arr[i]<<"\t";
        cout<<endl;
}
int main(){
        //Integer array declaration and initilization
        int a1[]={1,2,3,4,5};
        //Integer Character declaration and initilization
        char a2[]={'a','b','c','d','e'};
        //print the interger array
        printArray(a1,5);
        //print the character array
        printArray(a2,5);
}

===========================================================================

Task 2:Using the player switch portion of the tic tac toe game, create a function that does the switch. This is a practice in applying local variables, parameters, and global variables.

//globol variables to represent turn
string turn;
//the mySwitch to turn player turn
void mySwitch(string nextTurn){
        //if present turn is player 'X'
        //and nextTurn='O' then we switch player 
        //turn="O"
    if (turn=="X" && nextTurn=="O") {
                turn = "O";
        } 
        else 
        //if present turn is player 'O'
        //and nextTurn='X' then we switch player 
        //turn="X"
        if (turn=="O" && nextTurn=="X"){
                turn = "X";
        }
        else
                cout<<"Invaid Input ";
}

Related Solutions

You will overload a function named printArray. The function will assign values to each element and...
You will overload a function named printArray. The function will assign values to each element and print out a single dimension array of integers and an array of characters. The main body of the program will call each function. In C++
Define a function named posterize. This function expects an image and a tuple of RGB values...
Define a function named posterize. This function expects an image and a tuple of RGB values as arguments. The function modifies the image like the blackAndWhite function developed in Chapter 7 and shown below, but it uses passed in RGB values instead of black. def blackAndWhite(image): """Converts the argument image to black and white.""" blackPixel = (0, 0, 0) whitePixel = (255, 255, 255) for y in range(image.getHeight()): for x in range(image.getWidth()): (r, g, b) = image.getPixel(x, y) average =...
In c++ Write a recursive driver function that will replace each of the odd values in...
In c++ Write a recursive driver function that will replace each of the odd values in a stack with the cube of the value.
Take the following program and include overload functions into it. Display result of function. C++ Program:...
Take the following program and include overload functions into it. Display result of function. C++ Program: #include <iostream> using namespace std; // this is the additional function string read() {     string input;     cout << "Enter input: ";     cin >> input;     return input; } int main() {     // call function here     string output = read();     cout << "You entered: " << output; }
Write a c statement to declare variables of primitive data types, and assign values to the...
Write a c statement to declare variables of primitive data types, and assign values to the variables. Use common control structure in c, such as if, switch, break, for, while statements. Write a c program that takes command line parameters, and perform some computation based on the command line input. Write c statements to generate random number within a certain range. Write a c statement to declare array variables of primitive data types, and assign values to the elements of...
Overload and test function getNum(int &) to work with a parameter of type double. 2. Overload...
Overload and test function getNum(int &) to work with a parameter of type double. 2. Overload and test function doubleNum(int) to also work with a parameter of type double. 3. Both functions for collecting input should validate such that negative values would not be allowed. Perform the following steps: a. Add the function prototypes at the top. b. In main(), add a new variable of type double. You can name it "value2" to distinguish from the other variable. c. Write...
in c++, please provide only a function. the function should be named "tally." it takes no...
in c++, please provide only a function. the function should be named "tally." it takes no parameters but returns an int. the first int should be 0, next being 1, then 2, etc.. will rate if correct. again should only be 1 function.
Create your own data type using a C++ structure. Assign values to a variable of that...
Create your own data type using a C++ structure. Assign values to a variable of that data type. Retrieve values from the variable of that data type. Description: In this lab you will choose the statements to create a program that: Creates a brand new data type called "Monster". Once created, creates a variable of type Monster and assign values to the variable and then display the contents. This lab will again take the form of a guided multiple-choice quiz...
For C++ Make a function that swaps the values that change the values between the parameters...
For C++ Make a function that swaps the values that change the values between the parameters as the following rule. The functions swap takes 2, 3 or 4 parameters and these functions are implemented as the overloading functions. swap(int &, int &) : change the values each other. swap(int &, int &, int &) : change the value with the order. [min, medium, max] swap(int &, int &, int &, int &) : change the value like circular-shift-right [A, B,...
MUST BE DONE IN C (NOT C++) Using an array and a function, print the values...
MUST BE DONE IN C (NOT C++) Using an array and a function, print the values of an array backwards. Please follow these guidelines: - Setup your array manually (whichever values you want, as many as you want and whichever datatype you prefer). - Call your function. You should send two parameters to such function: the array’s length and the array. - Inside the function, go ahead and print the array backwards. - Your function shouldn’t return anything
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT