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

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 an operational semantic for a while loop in c++
write an operational semantic for a while loop in c++
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.?
Carbohydrates are the main sources of fuel for the body. They’re broken down into glucose, which...
Carbohydrates are the main sources of fuel for the body. They’re broken down into glucose, which is “burned” as fuel for the body. i. What is expected to occur when the body’s supply of glucose runs out? ii. Would insulin or glucagon be of any importance in this regard? Explain your answer. iii. As a nurse on duty, a patient is brought to the emergency ward with symptoms of weakness, dizziness, headache and slight disorientation. The patient has a history...
Write a program using c++. Write a program that uses a loop to keep asking the...
Write a program using c++. Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit. Your program must have (and use) at least four VALUE...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT