Question

Hello, I need help understanding what happens to the value in each loop. I missed a...

Hello, I need help understanding what happens to the value in each loop. I missed a lot of class so I need help. I decoded the final message but I'm supposed to fill in tables for each function.

Homework 4: Program Trace

Check out this “instructional” video on decoding strings - http://www.youtube.com/watch?v=zdA__2tKoIU

Determine the output of the program below. You will receive no credit for a submission that shows no work. You must make variable tables and show how the values of the variables change as the program executes.

#include <iostream>

#include <string>

using namespace std;

string makeWord(int num [], int total)

{

      string alpha = "abcdefghijklmnopqrstuvwxyz!";

string returnWord = "";

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

            returnWord = returnWord + alpha[num[i]];

           

      return returnWord;

}

void fillArray(int numbers[], int set)

{

       if (set == 0)

       {      numbers[0] = 18;

              numbers[1] = 15;

              numbers[2] = 17;

              numbers[3] = 8;

              numbers[4] = 13;

              numbers[5] = 6;

       }

       else

       {      numbers[0] = 1;

              numbers[1] = numbers[2];

              numbers[2] = 4;

              numbers[3] = 0;           

              numbers[4] = numbers[3] + 10;                  

              numbers[5] = 26;                 

       }

}

int getNum(int& numbers)

{

      int i = numbers * 100 - (10 % 3);

      numbers++;

      return i;

      numbers--;

}

int main()

{

       int numbers[7];

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

       {

              fillArray(numbers, i);

              cout << makeWord(numbers, 6);

              if (getNum(i) < 0)

                     cout << "\t";

              else

                     cout << "\n";

       }

       system("pause");

}

Variable Table Example

Main function

i loop counter

Numbers

makeWord return value

getNum return value

0

1

2

You will need to provide table examples for the makeWord and fillArray functions.

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

Here getNum() function before return value will increment value of i . So the for loop inside main function will execute only 2 times, ie when i=0 and when i=2.

When i=0 after get num is called, value of I becomes i=1. Then getNum() returns a -1 to main function

When main function gets a value less than 0 , it will print a “tab”

After that main function for loop will again increment the value and value of I becomes i=2

When getNum() fuction is called gain with i=2; it makes value of i=3 and returns 199

When main function gets a value greater than 0 it will print a “newline”

So the final output:     spring       break!

Where spring and break! are tab separated and a newline character exist after break!

Add a comment
Know the answer?
Add Answer to:
Hello, I need help understanding what happens to the value in each loop. I missed a...
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
  • Hello in C#. I need help understanding and knwoing what i missed in my program. The...

    Hello in C#. I need help understanding and knwoing what i missed in my program. The issue is, the program is supposed to have user input for 12 family members and at the end of the 12 it asks for user to input a name to search for. When i put a correct name, it always gives me a relative not found message. WHat did i miss. And can you adjust the new code so im able to see where...

  • Hi, I need to change the conversion where stack is into a class stack and add...

    Hi, I need to change the conversion where stack is into a class stack and add a template <class type> PROMPT: write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. if the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format. #include #include #include #include #include using namespace std; double conversion(string); int...

  • Help with C++ reverse program with leading zeros. I need to put the line from the...

    Help with C++ reverse program with leading zeros. I need to put the line from the function that display the zeros in main not in the function. So how can I move the display with leading zeros in main. Thanks. Here is my code. #include <iostream> #include <cstdlib> #include <iostream> using std::cout; using std::cin; using std::endl; //function templates int reverseNum(int); int main() { //variables char buf[100]; int num; while (true) { //prompt user for input cout << "Enter the number...

  • I need a really good Pseudo/Algorithm code for this C++ program below. #include <iostream> #include<fstream> using...

    I need a really good Pseudo/Algorithm code for this C++ program below. #include <iostream> #include<fstream> using namespace std; int main() {    int low, high, i;//integer varaible    bool flag;//boolean flag    string a = "Enter two numbers(intervals): ";//string datatype    ofstream f;//fow writing to file    f.open("a.txt");    cout << a;    cin >> low >> high;    cout << "Prime numbers between " << low << " and " << high << " are: ";    do /*...

  • Can someone help me fill in the first part of this c++ code: I need it...

    Can someone help me fill in the first part of this c++ code: I need it to print the menu based on the day selected. #include #include using namespace std; int main(){ double sub_total=0,tax=0,total=0; string food1[3]={"T-Bone Steak","Pork Chops","Iceland Cod"}; double prices_f1[]={20.50,15.45,10.55}; string food2[3]={"Sirloin Steak","Salmon Fillet","Jumbo Shrimp"}; double prices_f2[]={30.35,24.50,15.50}; string food3[3]={"Pork Tenderloin","Buffalo Chicken Sandwhich","Avocado Burger"}; double prices_f3[]={10.60,15.60,25.60}; string drink1[3]={"Raspberry Sgroppino","Sparkling Apple Sangria ","Spiced Cranberry Rum"}; double prices_d1[]={2.55,5.75,4.25}; string drink2[3]={"Champagne Mojitos","Roman Hoilday Cocktail","Dry Martini"}; double prices_d2[]={1.5,3,25,8.45}; string drink3[3]={"Radler Beer","Port wine","Primm's"}; double prices_d3[]={3.55,2.25,4.45};...

  • Hello, I am working on a C++ pick 5 lottery game that gives you the option...

    Hello, I am working on a C++ pick 5 lottery game that gives you the option to play over and over. I have everything working right except that every time the game runs it generates the same winning numbers. I know this is an srand or rand problem, (at least I think it is), but I can't figure out what my mistake is. I've tried moving srand out of the loop, but I'm still getting the same random numbers every...

  • Create a program named Lab14B. You will create a nested loop in this program by putting...

    Create a program named Lab14B. You will create a nested loop in this program by putting Lab14A’s for loop inside a while loop. In the new while loop, you will read integers from the file, Lab14B.txt, and determine if the number is prime (using the copied loop from Lab14A). Stop the while loop when you reach the end of file. Copy your code from Lab14A into your new program Add a while not eof loop around that code, and also...

  • In Java, I have created a program which can generate passwords. Currently the program can generate...

    In Java, I have created a program which can generate passwords. Currently the program can generate a password through a menu system of which characters to use. To complete the project, I need a system which allows the user to generate another password after the first password is created. I also need a method to check whether or not the password is complex by checking if the generated password has 3 or more character types and then displaying whether or...

  • *** I need help identifying my incoming parameters, outgoing parameters, and return values in the C++...

    *** I need help identifying my incoming parameters, outgoing parameters, and return values in the C++ code below. There are 4 functions in the code below and the 3 fields for each function are bolded. Should one of the items not exist, put N/A. **** #include #include using namespace std; int input(long long); // function to Input of Base 2 value to enforce the entry of only 1's and 0's int input2(double); int Base10toBase2(long long); // Base 10 to Base...

  • The loop below stores the values 1 to 5 in myList: for (int i = 0;...

    The loop below stores the values 1 to 5 in myList: for (int i = 0; i < 5; i ++) { myList [ i ] = i + 1; //store values using a loop } The loop below prints the values from first to last in myList: for (int i = 0; i < myList.length; i++) { System.out.print(myList [ i ] + " "); } Use the examples on the slides to complete the lab below. Please submit the...

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