Question

C++ Programming - Design Process I need to create a flow chart based on the program...

C++ Programming - Design Process

I need to create a flow chart based on the program I have created. I am very inexperienced with creating this design and your help will be much appreciated. My program takes a string of random letters and puts them them order. Our teacher gave us specific functions to use. Here is the code:

//list of all the header files
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

//Here are the Function Prototypes
unsigned int put_block(char block, unsigned int position, char array[]);
char get_block(void);
unsigned int shift_right(unsigned int position);
unsigned int shift_left(unsigned int position);
bool compare_blocks(char robot, char in_slot);
char switch_blocks(char robot, unsigned int position, char array[]);

int main()
{//Start of main

   //List of variables

   unsigned int position, counter = 0, i, z, flag1 = 0, flag2 = 0, flag3 =0;
   char block, yn, robot, in_slot, slots[20];

   while (flag3 == 0)
   {
       for (z = 0; z < 20; z++)//This for loop is to set the initial array to NULL
       {
           slots[z] = '#';
       }

       cout << "Welcome to the intial loading screen for the Baby Block Robot." << endl;
       cout << "This robot is designed to take an assortment of blocks and place them in alphabetcial order in the slots provided." << endl;
       cout << endl << endl;
       cout << "Please enter the intial slot (1-20) where you would like the robot to start." << endl;
  
       while (flag1 == 0)
       {
           cin >> position;
           if (position >= 1 && position <= 20)//this if statement is used to determine the position of the robot entered by the user
           {
               flag1 = 1;
               cout << "You have chosen to start at the spot marked \"" << position << "\"." << endl;
               position -= 1;
           }
           else
           {
               cout << "Invalid intial starting point.Please try again." << endl;
           }
       }

       block = get_block(); //Fuction call fot the get_block function.

       while (position != 0)
       {
           position = shift_left(position);//Function call for the shift_left function.
       }

       put_block(block, position, slots); //Funtion call for the put_block function.

       for (i = 0; i < 19; i++)
       {
           flag2 = 0;
           while (position != 0)
           {
               position = shift_left(position);//Function call for the shift_left function.
           }
           block = get_block();//Fuction call fot the get_block function.
           robot = block;
           in_slot = slots[position];
           while (flag2 == 0)
           {
               robot = block;
               in_slot = slots[position];//this is what places the character in the slots.

               if (slots[position] == '#')//this is to test if the slot is empty or not
               {
                   cout << "Slot " << position + 1 << " empty. " << endl;
                   put_block(block, position, slots); //Funtion call for the put_block function.
                   flag2 = 1;
               }
               else
               {
                   cout << "Slot " << position + 1 << " contains a block " << endl;

                   if (compare_blocks(robot, in_slot))//Function call for the compare_blocks function.
                   {
                       block = switch_blocks(block, position, slots);//Function call for the shift_block function.
                       counter++;//used to count the number of switchs
                       position = shift_right(position);//Function call for the shift_right function.
                   }

                   else
                   {
                       position = shift_right(position);//Function call for the shift_right function.
                   }
               }
           }
       }
  
       cout << endl << endl;
       cout << "Your blocks have been sorted! In order they are as follows: " << endl;
  
       //this is used to print all the charcters enterd by the user after being sorted by the robot.
       for (z = 0; z < 20; z++)
       {
           cout << "\"" << slots[z] << "\" ";
       }
  
       cout << endl << endl;

       cout << endl << "This program switched approximately " << counter << " blocks to complete it's goal." << endl;

       cout << endl << endl;

       cout << "Would you like to sort another set? Y/N" << endl;
  
       //this while loop is used to ask the user if they want to run the program again or quit after the first run.
       int flag4 = 0;
       while (flag4 == 0)
       {
           cin >> yn;
           if (yn == 'Y' || yn == 'y' || yn == 'N' || yn == 'n')
           {
               if (yn == 'Y' || yn == 'y')
               {
                   cout << "Rebooting..." << endl;
                   flag4 = 1;
                   cout << endl << endl;
               }
               else
               {
                   cout << "Quiting..." << endl;
                   cout << "Have a great day..." << endl;
                   flag4 = 1;
                   flag3 = 1;
                   system("pause");
               }
           }
           else
           {
               cout << " Invalid character input.Enter \"Y\" or \"N\"" << endl;
           }
       }
   }
   return 0;
}//end of main
  

  
////////////////////////////////////////////////////////////////////////////
//                                                                       //
//                           List of Functions                           //
//                                                                       //
////////////////////////////////////////////////////////////////////////////

// Function get_block
// Reads in a single character value from the keyboard
// This is the input from the chute
// Returns: a single character
//
// Example function call:    block = get_block();

char get_block(void)
{
   cout << "Enter the current character in the block chute." << endl;
   char block;
   cin >> block;
   return block;
}

// Function put_block
// This function stores a character into the character array representing the slots
//
// Inputs:
// block - type char - The character to be inerted into a slot
// position - type unsigned int - index of the slot where the block will go
// array - type char - array of slots containing the blocks
//
// Returns:
// position - type unsigned int - the index of the slot where the block was placed
//
// Example function call:    put_block(block, position, slots);

unsigned int put_block(char block, unsigned int position, char array[])
{
   array[position] = block;
   cout << endl << endl;
   cout << "Block " << block << " inserted into slot " << position + 1 << endl;
   return position;
}

// Function shift_right
// This function increments the index simulating a movement of the robot
// to the next higher slot (index) of the array
//
// Inputs:
// position - type unsigned int - current slot position
//
// Returns:
// position - type unsigned int - The updated position which is input position + 1
//
// Example function call: position = shift_right(position)

unsigned int shift_right(unsigned int position)
{
   position++;
   cout << "Position right shifted to " << position + 1 << endl;
   return position;
}

// Function shift_left
// This function decrements the index simulating a movement of the robot
// to the next lower slot (index) of the array
//
// Inputs:
// position - type unsigned int - current slot position
//
// Returns:
// position - type unsigned int - The updated position which is input position - 1
//
// Example function call: position = shift_left(position)

unsigned int shift_left(unsigned int position)
{
   position--;
   cout << "Position left shifted to " << position + 1 << endl;
   return position;
}

// Function compare_blocks
// This function compares the value of the block held by the robot
// with the value of the block in a slot
//
// Inputs:
// robot - type char - value of block held by robot
// in_slot - type char - value of block in the slot
//
// Returns:
// true or false
// TRUE if block held by robot is LESS than or equal to the block in slot
// FALSE if block held by robot is GREATER than block in slot
//
// Example function call: if ( compare_blocks(robot_block, slot_block) )

bool compare_blocks(char robot, char in_slot)
{

   cout << endl << "Comparing robot block \"" << robot << "\" with the block in the slot \"" << in_slot <<"\"" << endl;
   if (robot <= in_slot)
   {
       cout << "returning true. Robot block LESS than or EQUAL to block in slot. " << endl;
       return true;
   }
   else
   {
       cout << "returning false. Robot block GREATER than block in slot. " << endl;
       return false;
   }
}

// Function switch_blocks
// This function switches the block held by the robot with a block in a slot.
// After the switch the robot is holding the block removed from the slot.
//
// Inputs:
// robot - type char - The block to be inserted into a slot
// position - type unsigned int - index of the slot where the block will go
// array - type char - array of slots containing the blocks
//
// Returns:
// robot - type char. The value of the block removed from the slot.
//
// Example function call: block = switch_blocks(block, position, array);

char switch_blocks(char robot, unsigned int position, char array[])
{
   char temp_hold;

   cout << "Switching blocks " << robot<< " with " << array[position] << endl;
   temp_hold = robot;
   robot = array[position];
   array[position] = temp_hold;
   return robot;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

using char signe signe signe char int bool unsigned aray position++ osition char robot cout.. cout z<20? No cout flag10 ? No

flag2 0; cout position z 20? NoYes No osition cout flag4 0? Yes No Yes robot cin yn; slots.. Yes No No,Yes coutcout cout Code#include «iomanip> #include «iostream» Finclude algorithm #include «string» Here are the using namespace sunction Prototvnes

char get_block(void unsigned int put_block(char block, unsigned int position, char arrayl) unsigned int shift_right(unsigned

unsigned int shift_left(unsigned int position) Function shift_left This function decrements the index simulating a movement ochar switch_blocks(chär robot, unsigned int osition, char arrayl Function switch_blocks This function switches the block held

ool compare blocke (char Function compare blocks Thls function compares the value of the block he ld by the robot win the val

まinclude <iomanip> Buy Visustin har get block(voi include <iostream> pinclude algoritm> #include <string> Buy isustin int mai19 No Yes this is used to print cout e all the charcters enterd cout ce Your blocks have been sorted by the user after beingcoutQuiting.. endl coul << Have a great day. ·<< endl; cout <Rebootingend ag4-1 cout< endl end position shit rightposition

Add a comment
Know the answer?
Add Answer to:
C++ Programming - Design Process I need to create a flow chart based on the program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem with C++ program. Visual Studio say when I try to debug "Run-Time Check Failure #2...

    Problem with C++ program. Visual Studio say when I try to debug "Run-Time Check Failure #2 - Stack around the variable 'string4b' was corrupted. I need some help because if the arrays for string4a and string4b have different sizes. Also if I put different sizes in string3a and string4b it will say that those arrays for 3a and 3b are corrupted. But for the assigment I need to put arrays of different sizes so that they can do their work...

  • Prepare a design for the Baby Block Robot. The design should be in flow diagram form....

    Prepare a design for the Baby Block Robot. The design should be in flow diagram form. This diagram should help you identify the sequence of steps needed to solve specific situations that the robot will encounter. Be specific. Break down the actions into small steps. Test you design by using example block sequences. Think it through. I would expect the diagram to require multiple pages. If you have a program that supports flow diagrams, like PowerPoint, then use that. Hand...

  • C++ problem where should I do overflow part? in this code do not write a new...

    C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...

  • /// c ++ question plz help me fix this not a new code and explain to...

    /// c ++ question plz help me fix this not a new code and explain to me plz /// Write a function to verify the format of an email address: bool VeryifyEmail(char email[ ]); Do NOT parse the email array once character at a time. Use cstring functions to do most of the work. Take a look at the available cstring and string class functions on cplusplus website. Use a two dimensional array to store the acceptable top domain names:...

  • /* * Program5 for Arrays * * This program illustrates how to use a sequential search...

    /* * Program5 for Arrays * * This program illustrates how to use a sequential search to * find the position of the first apparance of a number in an array * * TODO#6: change the name to your name and date to the current date * * Created by Li Ma, April 17 2019 */ #include <iostream> using namespace std; //global constant const int ARRAY_SIZE = 10; //TODO#5: provide the function prototype for the function sequentialSearch int main() {...

  • * This program illustrates how to use a sequential search to find the position of the...

    * This program illustrates how to use a sequential search to find the position of the first apparance of a number in an array TODO#6: change the name to your name and date to the current date * * Created by John Doe, April 17 2019 */ #include using namespace std; //global constant const int ARRAY_SIZE = 10; //TODO#5: provide the function prototype for the function sequentialSearch int main() { //TODO#1: declare an integer array named intList with size of...

  • For a C program hangman game: Create the function int play_game [play_game ( Game *g )]...

    For a C program hangman game: Create the function int play_game [play_game ( Game *g )] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...

  • I have to type and explain in class each code in every detail filled with //...

    I have to type and explain in class each code in every detail filled with // commentary. Explains how does work in every codes. 1) What does the below print #include <iostream> using namespace std ; int main() {    int var1 = 20 ;    int var2 = 30 ;    int* ptr1 ;    int* ptr2 ;    int* temp ;    ptr1 = &var1 ;    ptr2 = &var2 ;    cout << *ptr1 << endl ;...

  • In c++ programming, can you please edit this program to meet these requirements: The program that...

    In c++ programming, can you please edit this program to meet these requirements: The program that needs editing: #include <iostream> #include <fstream> #include <iomanip> using namespace std; int cal_avg(char* filenumbers, int n){ int a = 0; int number[100]; ifstream filein(filenumbers); if (!filein) { cout << "Please enter a a correct file to read in the numbers from"; }    while (!filein.eof()) { filein >> number[a]; a++; } int total = number[0]; for (a = 0; a < n; a++) {...

  • This is for a C++ program: I'm almost done with this program, I just need to...

    This is for a C++ program: I'm almost done with this program, I just need to implement a bool function that will ask the user if they want to repeat the read_course function. I can't seem to get it right, the instructions suggest a do.. while loop in the main function. here is my code #include <iostream> #include <cstring> #include <cctype> using namespace std; const int SIZE = 100; void read_name(char first[], char last[]); void read_course(int & crn, char des[],...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT