Had some trouble finding all the errors in this C++ code. Problem 2: Finding Errors [6 P
Fantastic news! We've Found the answer you've been seeking!
Question:
Had some trouble finding all the errors in this C++ code.
Transcribed Image Text:
Problem 2: Finding Errors [6 P The code to be examined contains at least one error (one example error is given in Code 1): Example Code 1 Line Command 1 2 3 4 int main() { int a=0; double threshold = 10 For example: a semicolon is missing here std::cin >> a; if (a>>threshold) { else{ 6 7 8 9 } 10 } std::cout < < "a is greater than the threshold"; std::cout < < "a is smaller than or equal to the threshold"; Code to be Examined: Command #include Line 1 2 3 4 }; struct Values { double a = 0, b = 0; double Multiplying Values (Values z) { double y = x.a * x.b; return y; double DividingValues (Values g) { double y = 0; if (g.b (double)0) y = g.ag.b; else std::cout < < "Division by zero error" < < std::endl; return g; 5 6 7 8 } 9 10 11 12 13 14 } 15 int main() { 16 Values x; 17 18 19 20 21 22 23 } std::cout < < "Define value for a = "; std::cin >> x.x; std::cout < < "Define value for b = "; std::cin >> x.y; std::cout < < "b times a = " < < MultiplyValues(x) < < std::endl; std::cout < < "b divided by a = " < < DivideValues(x) < < std::endl; Problem 2: Finding Errors [6 P The code to be examined contains at least one error (one example error is given in Code 1): Example Code 1 Line Command 1 2 3 4 int main() { int a=0; double threshold = 10 For example: a semicolon is missing here std::cin >> a; if (a>>threshold) { else{ 6 7 8 9 } 10 } std::cout < < "a is greater than the threshold"; std::cout < < "a is smaller than or equal to the threshold"; Code to be Examined: Command #include Line 1 2 3 4 }; struct Values { double a = 0, b = 0; double Multiplying Values (Values z) { double y = x.a * x.b; return y; double DividingValues (Values g) { double y = 0; if (g.b (double)0) y = g.ag.b; else std::cout < < "Division by zero error" < < std::endl; return g; 5 6 7 8 } 9 10 11 12 13 14 } 15 int main() { 16 Values x; 17 18 19 20 21 22 23 } std::cout < < "Define value for a = "; std::cin >> x.x; std::cout < < "Define value for b = "; std::cin >> x.y; std::cout < < "b times a = " < < MultiplyValues(x) < < std::endl; std::cout < < "b divided by a = " < < DivideValues(x) < < std::endl;
Expert Answer:
Answer rating: 100% (QA)
Error 1 Missing Semicolon Line 6 In the MultiplyingValues function C double y xaxb Missing semicolon Theres a missing semicolon after this line A semi... View the full answer
Related Book For
Principles Of Econometrics
ISBN: 9781118452271
5th Edition
Authors: R Carter Hill, William E Griffiths, Guay C Lim
Posted Date:
Students also viewed these operating system questions
-
Suppose your sister and brother-in-law undergo genetic testing. The test reveals a 95 percent probability that their child will be born normal, but there is a 5 percent chance of severe mental and...
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
re Regular Languages and Finite Automata (a) Let L be the set of all strings over the alphabet {a, b} that end in a and do not contain the substring bb. Describe a deterministic finite automaton...
-
1. Dependence of business on environment (Define) 2. Business and environment ethics (Define) 3. Ethical behaviour includes 1) 2) 3) Business and Ecological (environmental ethics)
-
Using the headings of the synoptic journal for Dr. Duncan (Figure 11-2), indicate when postings would occur. 2013 May 3 7 14 17 Nick Olden invested $4,000 in his dental business. Paid three months'...
-
Define brand equity. What competitive advantages does high brand equity provide a company?
-
evaluate the concept of a 360-degree feedback appraisal system and its challenges; and
-
Presented below are a number of operational guidelines and practices that have developed over time. Instructions Select the assumption, principle, or constraint that most appropriately justifies...
-
One function of breakeven analysis is to create profits describe leverage evaluate the profitability of various sales levels determine the amount of financing needed by the firm The preferred...
-
You are the project manager for a new web-based online shopping system. Due to market competition, your management has directed you to go live with your systems one week earlier than originally...
-
You have a credit card with a nominal (stated) interest rate of 24%, and an effective annual interest rate (EAR) of 26.5319%. How many times per year must you pay your credit card bill?
-
Let M be the Turing machine defined by 8 90 91 92 B 91, B, R 91, B. R 91, a, R 92, b, L b 91, b, R 92, a, L 92, C, L a) Trace the computation for the input string abcab. b) Trace the first six...
-
Question 2 Your company is in the process of restructuring the company's capital structure. As the company's Head of Finance, you have been given the responsibility to determine the optimal capital...
-
When your friend argues that people can become good leaders when they receive training, which theory is this argument best aligned with?
-
1. The Ryobi Co. has no units in beginning work in process inventory. During the month, it had started 7,000 units into production. At the end of the month, 500 units remained still process which is...
-
Write a Python code for the payroll system of Employees in a company as follows: The program should have 4 classes: 1- Employee class: 5 points Use init () for initializing the attributes of the...
-
Holtzman Corporation tena un saldo al 1/1/07 en la provisinpara cuentas dudosas de $10,000. Durante 2007, cancel $7,200 decuentas y recaud $2,100 en cuentas previamente canceladas. Elsaldo 1 answer
-
Why is the national security argument for tariffs questionable?
-
Continuation of E9-32, E9-33, E9-34: memo (Learning Objective 5)} Use your results from E9-32, E9-33, and E9-34 to write a memo to Deer Valley's Director of Finance Jim Madsen recommending whether...
-
Calculate NPV with and without residual value (Learning Objective 4) Refer to the Deer Valley Expansion Data Set. 1. What is the project's NPV? Is the investment attractive? Why or why not? 2. Assume...
-
Calculate IRR with no residual value (Learning Objective 4) Refer to the Deer Valley Expansion Data Set. Assume that the expansion has no residual value. What is the project's IRR? Is the investment...
Study smarter with the SolutionInn App