Question

Help with programming in C++ Phase 1 is complete, please help with phase 2. Thank you....

Help with programming in C++

Phase 1 is complete, please help with phase 2. Thank you.

Phase 1

You must design 3 algorithms, and provide both a flow chart and pseudo code for the algorithms.
  

Algorithm descriptions:

Given an integer parameter named current_number and two constant global variables:
const int MIN_NUMBER = 1;
const int MAX_NUMBER = 8;

Create an algorithm named forward, that will advance ONE value through a sequence of numbers 1, 2, 3 ... MAX_NUMBER. In other words, when passed a value of 3 in the parameter current_number, it simply returns a 4.

However, when MAX_NUMBER is reached the algorithm should wrap around back and return MIN_NUMBER. The algorithm will NEVER return a value larger than MAX_NUMBER.

Create an algorithm named backward, that will move through a sequence of numbers ... 3, 2, MIN_NUMBER. In other words, when passed a value of 6 in the parameter current_number, it simply returns a 5.

When MIN_NUMBER is reached the algorithm should STOP and return the value MIN_NUMBER. This algorithm will NEVER wrap around.

Create an algorithm named createFileName, that takes a number as input, current_number, and builds and returns a string like "pictureX.gif", where X is the value in the input parameter.

This should fit on 1 sheet of paper. Place the 3 flowcharts (one per function) on one side of the paper and the matching pseudo-code next to it or on the other side.

Phase 2

Implement your algorithms with three functions for this phase. The functions should behave as described in phase 1. The forward function should wrap around when it reaches the last number, the backward function should stop when it reaches the first number.

Add the MIN_NUMBER and MAX_NUMBER constants at the top of your class, you will also need to add a global variable at the top of your class:

const int MIN_NUMBER = 1;
const int MAX_NUMBER = 8;
int image_number = 1;

The forward() and backward() functions MUST use an input parameter and output a return value, they DO NOT use the above global variable image_number directly, but they should use the constants. The functions are very simple when the current image number is 3 forward changes it to a 4 and returns it. When the current image number is 6 backward() changes it to a 5 and returns it. The function createFileName() will take a number as input, and returns a string containing a file name like "pictureX.gif". The function createRandomName() has no input, and returns a string containing a file name like "pictureX.gif".

Implement the following functions

int  forward ( int current_number ) {
    // return the new image number
}

int  backward ( int current_number ) {
    // return the new image number
}

 // use the constants MIN_NUMBER, MAX_NUMBER, do not use hard coded 1 or 8


string  createFileName ( int current_number ) {
    // return a filename like pictureX.gif
}

string  createRandomName (  ) {
    // return a filename like pictureX.gif
        // using a RANDOM number between MIN_NUMBER and MAX_NUMBER 
}

void  showMenu (  ) {
    // write a loop
    // Display a menu, with options 1 .. N for each function above, and an exit option
        // get user input and call the correct function using a SWITCH
        // print out the NEW image number everytime the value changes
}

int main () {
  //  call showMenu
  return 0;
}

The menu should have options for calling forward(), backward(), createFileName () and createRandomName ( ). Be sure to use a parameter when calling the functions, then use the return value to update the global image number. At this point, your program will show the menu, call the functions and print onto the console the new image number every time it changes.

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

// C++ program to implement the functions
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;

// use the constants MIN_NUMBER, MAX_NUMBER, do not use hard coded 1 or 8
const int MIN_NUMBER = 1;
const int MAX_NUMBER = 8;
int image_number = 1;

int forward ( int current_number ) {

   // return the new image number
   if((current_number+1) > MAX_NUMBER)
       return MIN_NUMBER;
   else
       return current_number+1;
}

int backward ( int current_number ) {
// return the new image number
   if((current_number-1) < MIN_NUMBER)
           return MAX_NUMBER;
       else
           return current_number-1;
}

string createFileName ( int current_number ) {
// return a filename like pictureX.gif
   return "picture"+to_string(current_number)+".gif";
}

string createRandomName ( ) {
// return a filename like pictureX.gif
// using a RANDOM number between MIN_NUMBER and MAX_NUMBER
   int num = rand()%(MAX_NUMBER-MIN_NUMBER+1) + MIN_NUMBER;
   return createFileName(num);
}

void showMenu ( ) {
// write a loop
// Display a menu, with options 1 .. N for each function above, and an exit option
// get user input and call the correct function using a SWITCH
// print out the NEW image number everytime the value changes
   int choice;
   do
   {
       cout<<"1. Forward"<<endl;
       cout<<"2. Backward"<<endl;
       cout<<"3. CreateFileName "<<endl;
       cout<<"4. CreateRandomName "<<endl;
       cout<<"5. Exit"<<endl;
       cout<<"Enter your choice: ";
       cin>>choice;

       switch(choice)
       {
       case 1:
           image_number = forward(image_number);
           cout<<"Image number: "<<image_number<<endl;
           break;
       case 2:
           image_number = backward(image_number);
           cout<<"Image number: "<<image_number<<endl;
           break;
       case 3:
           cout<<createFileName(image_number)<<endl;
           break;
       case 4:
           cout<<createRandomName()<<endl;
           break;
       case 5:
           break;
       default:
           cout<<"Invalid choice"<<endl;
       }
   }while(choice != 5);
}

int main() {
   srand(time(NULL));
   showMenu();
   return 0;
}
//end of program

Output:

Add a comment
Know the answer?
Add Answer to:
Help with programming in C++ Phase 1 is complete, please help with phase 2. Thank you....
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
  • Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a...

    Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a function that finds if a given value is present in a linked-list. The function should look for the first occurrence of the value and return a true if the value is present or false if it is not present in the list. Your code should work on a linked-list of any size including an empty list. Your solution must be RECURSIVE. Non-recursive solutions will...

  • Please help with this function i'm having trouble with: must be written in c++ All of...

    Please help with this function i'm having trouble with: must be written in c++ All of the functions you must write take at least two parameters: an array of strings, and the number of items the function will consider in the array, starting from the beginning. Your implementations must not use any global variables whose values may be changed during execution. Your program must build successfully under both Visual C++ and either clang++ or g++. Your program must not use...

  • C++ programming question, please help! Thank you so much in advance!!! In this exercise, you will...

    C++ programming question, please help! Thank you so much in advance!!! In this exercise, you will work with 2 classes to be used in a RPG videogame. The first class is the class Character. The Character class has two string type properties: name and race. The Character class also has the following methods: a constructor Character(string Name, string Race), that will set the values for the name and the race variables set/get functions for the two attributes a function print(),...

  • Python help! Any help is appreciated, thank you! Fill in the missing function, monthString(), in the...

    Python help! Any help is appreciated, thank you! Fill in the missing function, monthString(), in the program. The function should take number between 1 and 12 as a parameter and returns the corresponding month as a string. For example, if the parameter is 1, your function should return "January". If the parameter is 2, your function should return out "February", etc. def monthString(monthNum): """ Takes as input a number, monthNum, and returns the corresponding month name as a string. Example:...

  • help ASAP 3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and...

    help ASAP 3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and an int parameter. If both string parameters represent binary numbers and the int parameter is equal to a positive number less than or equal to the length of the longest string parameter, the function should return a binary string whose length is equal to two times the length of the maximum length of the two string parameters whose value is equal to the sum...

  • I need help implementing class string functions, any help would be appreciated, also any comments throughout...

    I need help implementing class string functions, any help would be appreciated, also any comments throughout would also be extremely helpful. Time.cpp file - #include "Time.h" #include <new> #include <string> #include <iostream> // The class name is Time. This defines a class for keeping time in hours, minutes, and AM/PM indicator. // You should create 3 private member variables for this class. An integer variable for the hours, // an integer variable for the minutes, and a char variable for...

  • Please help with this function i'm having trouble with: must be written in c++ All of...

    Please help with this function i'm having trouble with: must be written in c++ All of the functions you must write take at least two parameters: an array of strings, and the number of items the function will consider in the array, starting from the beginning. Your implementations must not use any global variables whose values may be changed during execution. Your program must build successfully under both Visual C++ and either clang++ or g++. Your program must not use...

  • Assignment 1 In this assignment you will be writing a tool to help you play the...

    Assignment 1 In this assignment you will be writing a tool to help you play the word puzzle game AlphaBear. In the game, certain letters must be used at each round or else they will turn into rocks! Therefore, we want to create a tool that you can provide with a list of letters you MUST use and a list of available letters and the program returns a list of all the words that contain required letters and only contain...

  • can someone please help me solve these problem in c++ language and leave useful comments below...

    can someone please help me solve these problem in c++ language and leave useful comments below so i can follow along and know what i am doing /view wa New Tab CSSO IDE 15 THE DIGIT SWAP PROBLEM Write a function named swapDigitPairs() that accepts a positive integer n as an input-output parameter which is changed to a new value similar to n's but with each pair of digits swapped in order. For example: int n = 482596; int old...

  • c++ Error after oveloading, please help? LAB #8- CLASSES REVISITED &&    Lab #8.5 …      Jayasinghe...

    c++ Error after oveloading, please help? LAB #8- CLASSES REVISITED &&    Lab #8.5 …      Jayasinghe De Silva Design and Implement a Program that will allow all aspects of the Class BookType to work properly as defined below: class bookType { public:    void setBookTitle(string s);            //sets the bookTitle to s    void setBookISBN(string ISBN);            //sets the private member bookISBN to the parameter    void setBookPrice(double cost);            //sets the private member bookPrice to cost    void setCopiesInStock(int noOfCopies);            //sets the private member copiesInStock to...

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