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++
Create a variable named specChars and assign it the values of all the punctuation items available...
Create a variable named specChars and assign it the values of all the punctuation items available on the top row of the keyboard, starting with the value above the number 1 through the value above the number 0. For example: !@#........ Prompt the user to enter a number between 1 and 10. For the number of times given by the user, randomly select one of the punctuation items in the specChars variable using the random.choice() function. Print the value that...
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...
Code in C++ Assign negativeCntr with the number of negative values in the linked list. #include...
Code in C++ Assign negativeCntr with the number of negative values in the linked list. #include <iostream> #include <cstdlib> using namespace std; class IntNode { public: IntNode(int dataInit = 0, IntNode* nextLoc = nullptr); void InsertAfter(IntNode* nodePtr); IntNode* GetNext(); int GetDataVal(); private: int dataVal; IntNode* nextNodePtr; }; // Constructor IntNode::IntNode(int dataInit, IntNode* nextLoc) { this->dataVal = dataInit; this->nextNodePtr = nextLoc; } /* Insert node after this node. * Before: this -- next * After: this -- node -- next */...
C++ Assume you need to test a function named inOrder. The function inOrder receives three int...
C++ Assume you need to test a function named inOrder. The function inOrder receives three int arguments and returns true if and only if the arguments are in non-decreasing order: that is, the second argument is not less than the first and the third is not less than the second. Write the definition of driver function testInOrder whose job it is to determine whether inOrder is correct. So testInOrder returns true if inOrder is correct and returns false otherwise. ....
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT