Concept explainers
Explanation of Solution
double conversion = 2.5; //Line 1
The above declaration is a correct one as the variable is correctly declared and initialized with a floating-point number.
char grade = 'B+'; //Line 2
The above declaration is incorrect as a char type variable is just a single character, whereas here we have two characters, B and +. Hence, it should be declared as a string type. The correct declaration would be:
string grade = "B+";
double 28.5 = num //Line 3
The above declaration is incorrect as the declaration does not end with a semi-colon. The correct one would be:
double 28.5 = num;
string message = ''First C++ course'; //Line 4
The above declaration is incorrect as the value must be within double quotes...
Trending nowThis is a popular solution!
Chapter 2 Solutions
C++ PROGRAMMING LMS MINDTAP
- #include <stdio.h>#include <stdlib.h> int cent50 = 0;int cent20 = 0;int cent10 = 0;int cent05 = 0; //Function definitionvoid calculateChange(int change) {if(change > 0) {if(change >= 50) {change -= 50;cent50++;} else if(change >= 20) {change -= 20;cent20++;} else if(change >= 10) {change -= 10;cent10++;} else if(change >= 05) {change -= 05;cent05++;}calculateChange(change);}} //Define the functionvoid printChange() { if(cent50)printf("\n50 Cents : %d coins", cent50); if(cent20)printf("\n20 Cents : %d coins", cent20); if(cent10)printf("\n10 Cents : %d coins", cent10); if(cent05)printf("\n05 Cents : %d coins", cent05);cent50 = 0;cent20 = 0;cent10 = 0;cent05 = 0; } //Function's definitionint TakeChange() { int change;printf("\nEnter the amount : ");scanf("%d", &change);return change; }//main functionint main() {//call the functionint change = TakeChange(); //use while-loop to repeatedly ask for input to the userwhile(change != -1){if((change %…arrow_forward#include <stdio.h>#include <stdlib.h> int cent50 = 0;int cent20 = 0;int cent10 = 0;int cent05 = 0; //Function definitionvoid calculateChange(int change) {if(change > 0) {if(change >= 50) {change -= 50;cent50++;} else if(change >= 20) {change -= 20;cent20++;} else if(change >= 10) {change -= 10;cent10++;} else if(change >= 05) {change -= 05;cent05++;}calculateChange(change);}} //Define the functionvoid printChange() { if(cent50)printf("\n50 Cents : %d coins", cent50); if(cent20)printf("\n20 Cents : %d coins", cent20); if(cent10)printf("\n10 Cents : %d coins", cent10); if(cent05)printf("\n05 Cents : %d coins", cent05);cent50 = 0;cent20 = 0;cent10 = 0;cent05 = 0; } //Function's definitionint TakeChange() { int change;printf("\nEnter the amount : ");scanf("%d", &change);return change; }//main functionint main() {//call the functionint change = TakeChange(); //use while-loop to repeatedly ask for input to the userwhile(change != -1){if((change %…arrow_forwardWrite a program that calculates the balance of a checking account at the end of a three- month period. It should ask the user for the starting balance. Then a loop (for loop is recommended) should iterate once for every month in the period, performing the followi 1. Ask the user for the total amount deposited into the account during that month. Do n accept negative number. This deposit should be added to the current balance to make current balance is up to date. 2. Ask the user for the total amount withdrawn from the account during that month. Do accept negative amount or amount greater than the current balance. The withdrawal amount should be subtracted from current balance, so current balance is up to date. 3. Update the total deposit. 4. Update the total withdrawal After the last iteration, the program should display the following information: 1. starting balance at the beginning of the three-month 2. total deposits/withdrawals made during the three-month period 3. final balance…arrow_forward
- Functions and Optionals - How do I do this practice exercise using Swift code?arrow_forwardAdmission Write a C++ program that: Define a void function named Admission() with two parameters. The function accepts two arguments: a student’s high school grade point average (for example, GPA is 3.2) and an admission test score (for example, 83). The function then displays a message “Accepted” if the student has any of the following: A GPA of 3.6 or above and an admission test score of at least 60. A GPA of 3.0 or above and an admission test score of at least 70. A GPA of 2.6 or above and an admission test score of at least 80. A GPA of 2.0 or above and an admission test score of at least 90. If the student does not meet any of the qualifications, the function should display a message “Rejected”. //for example, here is the function header: void admission (double gpa, int score) Write a function prototype statement for function Admission before the main function, and add function definition after the main function in the program. In the main function, prompts user to enter a…arrow_forwardQuestion1 Write a procedure to find the maximum of three numbers. Procedure specification: • Prototype: int max3(int a, int b, int c). - Parameter(s): a, b, c = Z. - Return value: the largest number among a, b and c. • e.g, max3(10, 20, 30) = 30, max3(1, 1, 1) = 1, max2(10, -20, -30) = 10 Main procedure specification: • • • Read three integers, a, b and c, using input macro. Call max3 procedure to find the largest. Display the result returned from your procedure using output macro.arrow_forward
- n. The memory for a static variable remains allocated betv Determine the value of each of the following expressions static_cast (toupper ('$')) a. b. static_cast (toupper ('3')) static_cast (toupper('#')) C. d. static cast (toupper ('d')) static cast (tolower('+')) e. f. static cast (tolower ('? ')) g. static cast (tolower ('H')) static_cast (tolower ('%') ) Determine the value of each of the following expressions: h. a. abs (12) b. fabs (23.45) c. fabs (-7.8) d. e. pow (4. g.arrow_forward38. To pass a scalar variable by reference in C++, you need to include the ____ operator before the formal parameter’s name in the receiving function’s header. a. & c. $ b. * d. @ 42. A simple, or ____ variable, is one that is unrelated to any other variable in memory. a. scalar b. vector c. independent d. dependent 43. You may use an assignment statement or the ____ operator to enter data into an array element. a. comparison b. arithmetic c. extraction d. insertion 44. Each of the ____ (variables) in an array has the same data type. a.elements b.objects c.structures d.subscriptsarrow_forwardComplete the following program When a machine reads blood pressure from a human body it displays two numbers they are called Systolicand Diastolic pressures. The program will take systolic and diastolic reading as input from the user and displays a message whether the person's blood pressure is "Normal" or "Elevated" or "High Blood Pressure". Program consists of two functions as follows. void input( .): This function is with two pass by reference parameters, and it reads input from the user. string process..): It receives two numbers(systolic and diastolic) and then it determines and returns a category according to the table below. Systolic |80 to 120 | 120 to 139 High blood equal and above 140 Diastolic Category Normal and 60 to 80 Elevated and 80 to 90 pressure above 90 or main () program is given below and you are asked to write the function definitions in the space provided below. #include #include using namespace std; void input(int &, int &); string process(int, int); int main()…arrow_forward
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,