Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Due Dates: ? Hierarchy chart, pseudocode for main, module specs for EACH functio

ID: 644967 • Letter: D

Question


Due Dates:
? Hierarchy chart, pseudocode for main, module specs for EACH function
? Source program (.cpp file) with screeen output:
Problem:
You are to write a program in C++ to play a guessing game. In this program, you'll
need 2 arrays (one array of ints of size 50 in main, one array of ints of size 20 in the
game function) and you'll write to a text file (declare the file variable in main).
In main, initialize the current index to 0, initialize the random seed, then in a loop,
do the following:
? **calculate a random number between 1 and 100 (inclusive) and assign to the
element in the main array at the current index. (see How to Use the Random
Functions below on page 3)
? call a function (that you write) to play the guessing game (one game) that returns
how many guesses the user made-- assign to a main variable (see details in A.
below)
? increment the current index
? repeat to ** if the current index < 50 AND the function that asks if the user wants
to continue returns true (see details in C. below)
After the main loop, call the selectionSort function EXACTLY AS IT'S WRITTEN IN
THE TEXTBOOK (you're NOT allowed to change it) so it sorts the main array. Then call
another function to write the array to a text file, and you MUST pass the current index
(indicating how many elements were assigned) as well as the main array (see details in
D. below).
You MUST declare as external consts 100 and 50 and 20, and use them in the program
(NEVER USE ANY LITERAL IN YOUR PROGRAM OTHER THAN 0 OR 1, other than in the
const declarations!
Function details:
A. In the function to play one guessing game, you MUST have an int "value" parameter
for the answer number (will be the current random number from main, but this
function doesn't need to "know" that). Inside the function declare an array of ints.
You'll be counting how many in-range and non-duplicate guesses the user made, so
you'll need to declare a local counter and initialize it to 0. Be sure to do the following:
? ***call a function to have the user guess a number (must not be guessed
already) (see B. below) The guess will be in the guessArray, but you are to also
assign it to a local int.
? check if the guess equals the game number (int parameter), is higher than the
game number, or lower than the game number (display a message to the screen
indicating the results of the comparison)
? repeat to *** if the user didn't guess the game number and the counter (of how
many guesses) < 20 (remember to use the const!)
CIS 22A
Prog. HW# 6

Explanation / Answer

#include "stdafx.h"

#include "stdio.h"

#include "conio.h"

#include "iostream"

#include "time.h"

using namespace std;

int searchList(const int list[], int numElems, int value)

{

int index = 0; // Used as a subscript to search array

int position = 1; // To record position of search value

bool found = false; // Flag to indicate if the value was found

while (index < numElems && !found)

{

if (list[index] == value) // If the value is found

{

found = true; // Set the flag

position = index; // Record the value's subscript

}

index++; // Go to the next element

}

return position; // Return the position, or ?1

}

void selectionSort(int array[], int size)

{

int startScan, minIndex, minValue;

for (startScan = 0; startScan < (size ? 1); startScan++)

{

minIndex = startScan;

minValue = array[startScan];

for(int index = startScan + 1; index < size; index++)

{

if (array[index] < minValue)

{

minValue = array[index];

minIndex = index;

}

}

array[minIndex] = array[startScan];

array[startScan] = minValue;

}

}

int guessgame(int value)

{

   

}

int guess()

{

       const string error1 = "Number out of range!!!";

       const string error2 = "Number already guessed!!!";

       int gnum;

       cout << "Guess a number : ";

       cin >> gnum;

       if ((gnum < 1) || (gnum>100))

              cout << error1;

}

void main()

{

       int main[50];

       int game[20];

       int rnum;

    for(int i=0;i<50;i++)

       {

        srand(time(NULL));

              rnum=rand()%100;

              if (rnum==0)

                     rnum=100;

              main[i]=rnum;

       }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote