Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need Help with the following C++ Questions: 1.Indicate what the logic error is in the following code and show how to fix it. if (pH

Need Help with the following C++ Questions:

1.Indicate what the logic error is in the following code and show how to fix it.

if (pH < 3) cout << "Solution is very acidic" << endl; else if (pH >= 3 && pH < 7) cout << "Solution is acidic" << endl; else if (pH == 7) cout << "Solution is neutral" << endl; else if (pH > 7 && pH < 12) cout << "Solution is alkaline" << endl; else if (pH > 12) cout << "Solution is very alkaline" << endl; else cout << "Invalid pH value" << endl;

2.

The purpose of this function is to return the maximum value of a set of numbers in a file.

Complete the body of the loop. Do not define any other variables.

int getMax ()

{

int val; int currentMax = 0;

ifstream infile("numbers.txt", ios::in); if (! infile.is_open()) return -1;

while (infile >> num) {

// show the code that goes here

}

return currentMax;

}

3.

You have the following definition:

struct Box

{

int height;

int width;

int length;

};

and variable declaration:

Box box1;

Fill in the operator needed here to access the height field.

box1 (answer need) height

4. Write a prototype for a function named swap that takes 2 integers (num1 and num2) as reference parameters and returns the maximum of the two integers. (Don't write the body of the function, just show the prototype.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions

Question

To find integral of sin(logx) .

Answered: 1 week ago

Question

18. If you have power, then people will dislike and fear you.

Answered: 1 week ago