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 drawn diagrams are acceptable - make sure that they are neat and are easy to read. You can take a picture of them and paste into a Word (or other ) doc to upload.
The baby block program instructions are:
Thank you for your purchase of the Baby Block 270 Robot (BB270). In order to use the BB270 you must write a program using the basic robot operations stated below:
Included with the robot are functions for each of the above operations coded in the C++ Programming Language. The code may be downloaded from the assignments tab in Canvas.
To test your robot write a program that will place a series of blocks into 20 slots in alphabetic order. Specifically the robot must be able to accomplish this task according to the following requirements:
Failure to comply with the above requirements will result in a 10% deduction for each requirement that is not met.
The Robot Challenge: Your robot will be judged by the fewest number of swapped blocks. To keep up with that number you will need to maintain a count of the number of times the Switch Blocks function is called.
Robot Test Cases
There are five test cases that your robot must pass. They are:
TEST CASE 1: "AXFIUTRPQVWSEYJINYTB"
TEST CASE 2: "ABFGHIJKMOPRSTUVWXYZ"
TEST CASE 3: "ZYXWVUTSRPOKJIIHGFBA"
TEST CASE 4: "AAAAAYYYYYQQQQQXXXXX"
TEST CASE 5: "XXXAAAZZZAAYYVVVVQQQ"
Six functions are provided to assist you with these test cases. By using these functions you do not have to enter each block one at time as required by the get_block function. There is one function for each individual test case plus another that can be used for any of the five individual test cases. All six functions return one block at a time.
Your output should show the configuration of the blocks in the slots after each block is placed. You may call the print_slots function to generate that output. You will also need to print out the number of times the robot switched blocks. (Number of times the switch_blocks function is called.
I really only need help with the design document.
Thank you!
#include
#include
#include
#include
#include
using namespace std;
char get_block(void);
unsigned int put_block(char block, unsigned int position, char
array[]);
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[],
unsigned int &switch_count);
bool test_empty(unsigned int position, char array[]);
unsigned int findMid(char *blocks);
void printBlockLayout(char *blocks);
char *sort(char *blocks, unsigned int index, char
¤t_block, int &increment, unsigned int
&switch_count, unsigned int sort_iteration);
unsigned int search(char ¤t_block, char *blocks, unsigned
int increment_coefficient, int &increment, unsigned int
&switch_count);
int main(void){
char *blocks, current_block;
unsigned int start_pos = 0, increment_coefficient = 1, switch_count
= 0;
int increment = 1;
blocks = new char[20];
for(int i = 0; i < 20; i++)
blocks[i] = 0; //Initialize all of the elements in our block array
to zero.
cout << "Hello, I am the Baby Block 270 Robot. Please specify
the starting slot (0-19):" << endl;
cin >> start_pos;
cout << left << "Your starting position is " <<
start_pos << "." << endl;
cout << "Please enter character for the first block."
<< endl;
blocks[start_pos] = get_block();
printBlockLayout(blocks);
for(int j = 0; j < 19; j++){
cout << "Please enter a character for the next block"
<< endl;
if(j < 9)
increment_coefficient = 2;
else
increment_coefficient = 1;
current_block = get_block();
blocks = sort(blocks, search(current_block, blocks,
increment_coefficient, increment, switch_count), current_block,
increment, switch_count, 0);
printBlockLayout(blocks);
}
cout << "Total switch count: " << switch_count <<
endl;
return 0;
}
void printBlockLayout(char *blocks){
cout << endl << "Current block layout: " <<
endl;
for (int i = 0; i < 20; i++) {
if (blocks[i] != 0)
cout << setw(3) << blocks[i];
else
cout << setw(3) << "-";
}
cout << endl;
}
unsigned int findMid(char *blocks){ //Function used to find the
index of the current middle baby block.
unsigned int N = 0, mid = 0, index = 0;
for(int i = 0; i < 20; i++){
if(blocks[i] != 0)
N++;
}
if(N % 2 == 0)
mid = N/2;
else
mid = (N/2)+1;
for(int i = 0; i < 20; i++){
if(blocks[i] != 0)
index++;
if(index == mid)
return i;
}
}
unsigned int search(char ¤t_block, char *blocks,
unsigned int increment_coefficient, int &increment, unsigned
int &switch_count){
unsigned int index = 0;
index = findMid(blocks);
if(current_block > blocks[index])
increment = 1*increment_coefficient;
else if(current_block < blocks[index]){
increment = -1*increment_coefficient;
}
else
return index;
do{
index += increment;
}
while(!(index >= 19 || index <= 0
|| (current_block > blocks[index] && current_block >
blocks[index+increment] && increment < 0)
|| (current_block < blocks[index] && (current_block <
blocks[index+increment] || blocks[index+increment] == 0) &&
increment > 0)
|| (current_block == blocks[index]))
|| !(test_empty(index,blocks)));
if(index < 19 && index > 0){ //if we're not
outside of the array..
if(test_empty(index,blocks))
return index;
if(current_block < blocks[index] && increment >
0)
increment *= -1; //We'll need to go backwards to sort from here
on.
//if((current_block > blocks[index] && increment <
0))
if((current_block > blocks[index] && increment > 0 ||
current_block < blocks[index] && increment <
0)){
index += increment;
if(test_empty(index,blocks))
return index;
}
current_block = switch_blocks(current_block, index, blocks,
switch_count); //We'll switch the blocks.
return index + increment; //then we need to send our new current
block into the sorting function with the next index
}\
else{ //But if we ARE outside of the array
if (index >= 19) { //then if we're to the right of the max
index
index = 19;
if(test_empty(index,blocks)) //We now need to see if it's empty. If
it is, we will just put the block down
return index;
else{
if (current_block < blocks[index] && increment >
0){
index -= increment; //If we've hit the end of the index and our
current block doesn't fit there, we'll need to step back towards
the center.
}
current_block = switch_blocks(current_block, index, blocks,
switch_count); //If not, we'll need switch the current block with
the last block in the array, at index 19.
increment *= -1;
return index + increment; //Then we can take a step forwards or
backwards from the first or last index before we send it to the
sorting function.
}
}
else{ //If we're to the left of the min index
index = 0;
if(test_empty(index,blocks)) //We now need to see if it's empty. If
it is, we will just put the block down
return index;
else{
if (current_block > blocks[index] && increment < 0)
{
index -= increment; //If we've hit the end of the index and our
current block doesn't fit there, we'll need to step back towards
the center.
}
current_block = switch_blocks(current_block, index, blocks,
switch_count); //We'll need switch the current block with the first
block in the array, index 0.
increment *= -1;
return index + increment; //Then we can take a step forwards or
backwards from the first or last index before we send it to the
sorting function.
}
}
}
}
char *sort(char *blocks, unsigned int index, char
¤t_block, int &increment, unsigned int
&switch_count, unsigned int eoa_count){
if(index < 19 && index > 0){ //if we're not outside
of the array..
if(test_empty(index, blocks)) //see if the slot is empty
put_block(current_block, index, blocks); //if it is, put the block
there and be done.
else{ //if it's not empty
current_block = switch_blocks(current_block, index, blocks,
switch_count); //we'll switch the blocks
index += increment; //Then we can step to the next index.
blocks = sort(blocks, index, current_block, increment,
switch_count, eoa_count); //And use recursion to sort our new
current_block!
}
}
else{ //but if we ARE outside of the array..
if(index >= 19) { //If we're to the right of the max index
index = 19;
if(test_empty(index,blocks)) //See if it's empty and if we can just
put the block down
put_block(current_block, index, blocks);
else{ //If it's not empty
current_block = switch_blocks(current_block, index, blocks,
switch_count); //We'll need switch the current block with the last
block in the array, at index 19.
if(eoa_count == 0) ///If we reach the end of the array in our first
iteration, we need to switch the way that we're stepping.
increment *= -1; //But if it's not in the first iteration, we don't
want to keep switching the way that we're going.
index += increment; //So now we will be stepping backwards to
sort.
eoa_count++; //Increment the end of array count.
blocks = sort(blocks, index, current_block, increment,
switch_count, eoa_count); //And we can use recursion to sort the
rest.
}
}
if (index <= 0) { //Then if we're to the left of the min
index
index = 0;
if(test_empty(index,blocks)) //See if it's empty and if we can just
put the block down
put_block(current_block, index, blocks);
else{ //if it's not empty..
current_block = switch_blocks(current_block, index, blocks,
switch_count); //We'll need switch the current block with the first
block in the array, index 0.
if(eoa_count == 0) ///If we reach the end of the array in our first
iteration, we need to switch the way that we're stepping.
increment *= -1; //But if it's not in the first iteration, we don't
want to keep switching the way that we're going.
index += increment; //So now we will be stepping backwards to
sort.
eoa_count++;
blocks = sort(blocks, index, current_block, increment,
switch_count, eoa_count); //And we can use recursion to sort the
rest.
}
}
}
return blocks;
}
//
------------------------------------------------------------------------
//
//
//
//
//
//
Functions for the seven robot
operations
//
//
//
//
//
//
------------------------------------------------------------------------
//
//
// 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)
{
char block;
cin >> block;
block = toupper(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
*blocks)
{
blocks[position] = block;
cout << "Block " << block << "
inserted into slot " << position << 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 block in 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
*blocks, unsigned int &switch_count)
{
char temp_hold;
cout << "Switching blocks " << robot
<< " with " << blocks[position] << endl;
temp_hold = robot;
robot = blocks[position];
blocks[position] = temp_hold;
switch_count++;
return robot;
}
// Function test_empty
// This function tests the array to determine if a slot is empty
(NULL)
//
// Inputs:
// position - type unsigned int - index of slot to be tested
//
// Returns:
// true or false as value o function
// TRUE if slot is empty
// FALSE if the slot contains a block
//
// Example function call: if ( test_empty(index, array) )
//
bool test_empty(unsigned int position, char array[])
{
if (array[position] == 0)
{
cout << "Slot " <<
position << " empty. " << endl;
return true;
}
else
{
cout << "Slot " <<
position << " contains a block " << endl;
return false;
}
}
Prepare a design for the Baby Block Robot. The design should be in flow diagram form....
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...
Saving The Universe Again Problem An alien robot is threatening the universe, using a beam that will destroy all algorithms knowledge. We have to stop it! Fortunately, we understand how the robot works. It starts off with a beam with a strength of 1, and it will run a program that is a series of instructions, which will be executed one at a time, in left to right order. Each instruction is of one of the following two types: C...
Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? 3. Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two...
USE C programming (pls label which file is libcipher.h and libcipher.c) Q4) A shift cipher is one of the simplest encryption techniques in the field of cryptography. It is a cipher in which each letter in a plain text message is replaced by a letter some fixed number of positions up the alphabet (i.e., by right shifting the alphabetic characters in the plain text message). For example, with a right shift of 2, ’A’ is replaced by ’C’, ’B’ is...
Sutmissien shoud indude a cop file and an output file generated by your program. Plee smit the pp fie Do NOT submit the entire Visual Studio project package! Background hre s amous ralway staton in PopPush City. Country there is incredibly hilly. The station was built in st centiuny Unfortunately, funds were extremely limited that time. it was possible to establish only a sete res Moreover t turned out that the station could be only a dead-end one (see picture)...
You will use Quartus II to build an 8 bit arithmetic logic unit that performs the following functions: Control Value Function 000 Copy In1 to theResult unchanged 001 Copy In2 to theResult unchanged 010 Add In1 to In2 011 Subtract In2 from In1 100 And In1 and In2 101 Or In1 and In2 110 Shift left In1 by 1 bit 111 Shift right In1 by 1 bit You are allowed to use either gates/logic schematic, or else Verilog. We suggest...
You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...
#2 You are going to add more code to carClass.cpp. 0. Make sure you finished the lab part: goForward, turnRight(), getDirection(), getXO, getY() and get Modelo 1. Preparation: In the last lab, we tested our functions using cl. Comment out that section. Create c2 with any make and model. int main() Car cl("Toyota", "Camry") 77777777777777 lereate c2 here Tested the functions in the last lab cout <<cl.getModel() << endl; Comment out this section cout <<cl.getX() <<"*«<cl.getY() << endl; return 0;...
I need help with this code, I'm stuck on it, please remember step 4, I'm very much stuck on that part. It says something about putting how many times it appears Assignment #1: Sorting with Binary Search Tree Through this programming assignment, the students will learn to do the following: Know how to process command line arguments. 1 Perform basic file I/O. 2. Use structs, pointers, and strings. Use dynamic memory. 3. 4. This assignment asks you to sort the...
C++ Assignment 4 - Robot Speed Estimator Be sure to read through Chapter 7 Structured Data and Classes before starting this assignment. Your job is to write a program to estimate the speed of a robot. Your program will use a class called Robot to represent a robot. To keep things simple, this class will focus only on one aspect of a Robot - the maximum speed at which it can move. Background The speed of the robot is largely...