Question

In: Computer Science

a) Find a bug in the code snippet below. Assume that a, b, c and d...

a) Find a bug in the code snippet below. Assume that a, b, c and d are correctly declared and initialized integer variables.

a = b+c
if (a=d) then
  print *,”A equals to D”
else
  print *,”A does not equal D”
end if

b) Find a bug in the code snippet below. Assume that a,b,and c are correctly declared and initialized integer variables.

if (a+b) > c) then
  print *,”Sum of A+B is greater than C”

end if

Solutions

Expert Solution

Answer a:

Bug in code a is inside the if statement, For checking the condition to be equal using if statement we should us "==" for comparison inside the if statement,

So, instead of if (a=d) the correct statement should be if(a==d).

C++ bug free code for question a is:

#include<bits/stdc++.h>

using namespace std;

int main()

{

int a,b,c,d;

cout<<"enter the value of b,c,d"<<endl;

cin>>b>>c>>d;

a = b+c;

if(a==d)

{

cout<<"A equals to D";

}

else

{

cout<<"A does not equal D";

}

return 0;

}

Output screen:

Answer b:

Bug in the code b is inside the if condition, their is opening bracket missing of the condition.

Instead of if(a+b)>c) the statement should be if((a+b)>c).

C++ bug free code for question b is:

#include<bits/stdc++.h>

using namespace std;

int main()

{

int a,b,c;

cout<<"enter the value of a,b,c"<<endl;

cin>>a>>b>>c;

if((a+b)>c)

{

cout<<"Sum of A+B is greater than C";

}

return 0;

}

Output screen:

Thank you!!!


Related Solutions

[50%] Code Snippet Given snippet code below that you are required to complete. You are not...
[50%] Code Snippet Given snippet code below that you are required to complete. You are not allowed to make a new function or change any given code. Please complete each section that are marked with the notation “INSERT YOUR CODE HERE”. Once you complete the snippet below, your output should have the same result with the given output below. Descriptions: [15%] isValid() This function is for checking that there is no duplicated employee data in the linked list. This function...
Assume that: float a, b, c, d, f; and variables b, c, d, f are initialized....
Assume that: float a, b, c, d, f; and variables b, c, d, f are initialized. Write a line of c++ code that calculates the formula below and stores the result to the variable a:
Given the below Java code snippet, assuming the code is correct, and the names are meaningful,...
Given the below Java code snippet, assuming the code is correct, and the names are meaningful, select the best answer for the below questions: public static void main(String[] args) { int numStations = 10; int enter = 0; int exit = 0; Train train = new Train(numStations); for (int station = 0; station < numStations; station++) {      enter = enter + train.enterPassengers(station);      exit = exit + train.exitPassengers(station); } System.out.println("Number of passengers entered the train: " + enter); System.out.println("Number...
Find the value of a : b : c : d, if a : b = 2 : 3, b : c = 4 : 5 and c : d = 6 : 7.
Find the value of a : b : c : d, if a : b = 2 : 3, b : c = 4 : 5 and c : d = 6 : 7.
Find the (a) mean, (b) median, (c) mode, and (d) midrange. Listed below are the weights...
Find the (a) mean, (b) median, (c) mode, and (d) midrange. Listed below are the weights in pounds of 11 players randomly selected, from the roster of a championship sports team. 274 188 227 200 260 246 279 198 260 278 279 215 271
Write assembly code to implement the expression A = (B + C - D) x (D...
Write assembly code to implement the expression A = (B + C - D) x (D + E x F) on three-, two-, one-, and zero-address machines (do not change the values of the operands). Refer to Chapter 5 Slides 25-28 for the syntax.
1. Find the missing value A, B, C, D
Refer to the table below.QuantityVariable Cost (in dollars)Fixed Costs (in dollars)Total Costs (in dollars)Average Variable Costs (in dollars per unit)Average Total Costs (in dollars per unit)Marginal Costs (in dollars per unit)00A40------1154055155515235407517.537.520360401002033.3254904013022.532.530512540165C33356B40D26.633.3351. Find the missing value A, B, C, D2. Continue to refer to this table. If the firm produces 5 units that it sells for $40.00 each, what will its profits or losses equal?Select one:a. losses equal $75b. losses equal $35c. profits equal $75d. profits equal $353. Continue to refer...
Find the proof of the following ((a ∧ b) ∨ (c ∧ d)), (a → e),...
Find the proof of the following ((a ∧ b) ∨ (c ∧ d)), (a → e), (b → f), (c → f), (d → e) ⊢ e
Consider the cross: A/a; b/b; C/c; D/d; E/e x A/a; B/b; c/c; D/d; e/e a) what...
Consider the cross: A/a; b/b; C/c; D/d; E/e x A/a; B/b; c/c; D/d; e/e a) what proportion of the progeny will phenotypically resemble the first parent? b) what proportion of the progeny will genotypically resemble neither parent?
Below are the annual returns of the stock A, B, C and D and the market...
Below are the annual returns of the stock A, B, C and D and the market portfolio for the period 2018-2022. Find the expected return and standard deviation of the stock A, B, C, D and the market portfolio. PREPARED BY HANDWRITING. Year Prob. Asset A Asset B Asset C Asset D Market 2018 0,20 11,00 9,00 12,00 15,00 14,00 2019 0,25 13,00 11,00 15,00 13,00 12,00 2020 0,10 9,00 8,00 11,00 10,00 9,00 2021 0,20 12,00 12,00 11,00 13,00...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT