Question

In: Computer Science

(a) In C++, write down the main method including a for loop. The body of the...

(a) In C++, write down the main method including a for loop. The body of the for loop includes the followings :

i. an if condition

ii. an array (of any type & of any size)

iii. a structure variable (with at least two variables of any type)

(b) Show the corresponding code contents in memory for the main method and draw the stack contents while the main method starts execution and reaches at the line prior to return from your main method of Problem 3(a).

(c) Create a symbol table structure (dynamic scoping) at the line before returning from your main method of Problem 3(a).

Solutions

Expert Solution

(a) Code:

#include <iostream>

using namespace std;

struct Abc // initialise structure
{
int x1,y1;
};

int main()
{   
int arr[2]; //an array (of int type & of 2 size)
struct Abc y={6,8}; //a structure variable (with at least two variables of any type)
int x=0;
  
for(int i=1; i<=10; i++){
if(i==y.x1){ // if condition
arr[x]=i;
x++;
}
if(i==y.y1){
arr[x]=i;
x++;
}
}

for(int i=0; i<2; i++){
cout<<arr[i]<<" ";
}
}

Output:

Answering only (a) since this is a complete question in itself, please add other parts as separate questions


Related Solutions

Java Class Create a class with a main method. Write code including a loop that will...
Java Class Create a class with a main method. Write code including a loop that will display the first n positive odd integers and compute and display their sum. Read the value for n from the user and display the result to the screen.
Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three integer values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three int||eger values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
Write a complete Java program, including comments in both the main program and in each method,...
Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...
Write a complete Java program, including comments in both the main program and in each method,...
Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...
Write a complete Java program, including comments in both the main program and in each method,...
Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...
Write a program in c++, with at least four functions, including main, which must do the...
Write a program in c++, with at least four functions, including main, which must do the following: Ask user whether they want to encode or decode a message – if no, then terminate Take the input string from the user, store it in dynamic memory (use new) As appropriate, encode or decode the message using Rot13. Output the encoded/decoded message Delete the input string from dynamic memory (use delete) Input will be a string of no more than 25 characters....
Write a program that contains a main method and another method named userName. The main method...
Write a program that contains a main method and another method named userName. The main method should prompt the user to enter a full name. The userName method takes the full name as an argument and prints the name in reverse order and returns the number of characters in the name. See Sample Output (input shown in blue). Sample Output Please enter your FULL name Billy Joe McCallister Here is the name Billy Joe McCallister in reverse: retsillaCcM eoJ ylliB...
Write down the C++ Program
 Write a function, which accept three integer values as arguments find the largest of three and then return the largest value to main program. Write a main program which will call the function by passing three integer values and print the value returned by the function.?
write an operational semantic for a while loop in c++
write an operational semantic for a while loop in c++
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT