In: Computer Science
in C++
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 ";
}