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.
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!
Hello, I need help understanding what happens to the value in each loop. I missed a...
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...
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 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 /*...
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...
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...
Hello everyone! I am working on my assignment for C++ and I'm having a bit of trouble on the value producing functions, I am creating a program wherein I have to input a value and I need to create a function called square value where in it will square the value I have input. I cannot seem to figure out this part. Here is the code that I have so far, and thank you for any help. I greatly appreciate...
I know the output of the program I just want help with the logic of figuring out the output a step by step processes of how to get to the output. thank you this is for my study guide please include step by step processes of how to reach output thank you. #include <iostream> using namespace std; int funcB(int); int funcA(int n) { if (n <= 1) return 1; else return n + funcB(n - 2); } int funcB(int n)...
C++ assignment help! The instructions are below, i included the main driver, i just need help with calling the functions in the main function This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a...
I need help with the creation of the pre and post conditions for each function of my program. Please see below. #include <iostream> #include <string.h> using namespace std; #define TOTAL_COMMANDS 7 struct command { char name[1024]; // Store the name of the command int *paramsCount; // Stores the valid no. of params char error[4096]; // Stores the valid errors int differentParams; // Store no. of different ways to specify params int differentErrors; // Store no. of different ways to error...
CAN YU HELP ME CONSTRUCT A FLOW CHART FOR THE FOLLOW PROGRAM ? C++ CODE: #include<iostream> using namespace std; int main() { //declaring variable num int num; //prompting user to enter a number cout<<"Input a number to check prime or not:"; //reading input from user cin>>num; //loop to check user input for positive number while(num<0) { cout<<"Error! Positive Integers Only.\n"; cout<<"Input a number to check prime or not:"; cin>>num; } //initializing isPrime variable with false bool isPrime = true; //loop...