C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 2, Problem 23SA
The following program has syntax errors. Correct them. On each successive line, assume that any preceding error has been corrected. (12)
const char = STAR = '*'
const int PRIME = 71;
int main
{
int count, sum;
double x;
count = 1;
sum = count + PRIME;
x = 25.67
newNum = count * ONE + 2;
sum + count = sum;
(x + sum) ++;
x = x + sum * COUNT;
sum += 3 –;
cout << " count = " << count << ", sum = " << sum
<< ", PRIME = " << Prime << endl;
}
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
Language: JAVA
Leap-Year
Write a program to find if a year is a leap year or not. We generally assume that if a year number is divisible by 4 it is a leap year. But it is not the only case. A year is a leap year if −
It is evenly divisible by 100
If it is divisible by 100, then it should also be divisible by 400
Except this, all other years evenly divisible by 4 are leap years.
So the leap year algorithm is, given the year number Y,
Check if Y is divisible by 4 but not 100, DISPLAY "leap year"
Check if Y is divisible by 400, DISPLAY "leap year"
Otherwise, DISPLAY "not leap year"
For this program you have to take the input, that is the year number from an input file input.txt that is provided to you. The input file contains multiple input year numbers. Use a while loop to input the year numbers from the input file one at a time and check if that year is a leap year or not.
Create a class named LeapYear which will contain the main method and write all your code in the main…
int power(int base,int exp);
*This function accepts the
arguments for base and exponent
and returns power. The algorithm is
to repeatedly multiply the value of
the base to how many time the value
of exponent.*
For example:
Test Input Result
printf("%d",power(2,5)); 2 32
5
printf("%d",power(3,4)); 3 81
4
-Use C language, please. Thank you.
Correct the errors in the following code segment.
// This code contains ERRORS!
// Print the numbers 1 through 10.
for (int count = 1, count <= 10, count++;) {
System.out.println(count); count++;
}
Chapter 2 Solutions
C++ Programming: From Problem Analysis to Program Design
Ch. 2 - 1. Mark the following statements as true or...Ch. 2 - Prob. 2MCCh. 2 - Which of the following is not a reserved word in...Ch. 2 - Prob. 4SACh. 2 - 5. Are the identifiers quizNo1 and quiznol the...Ch. 2 - 6. Evaluate the following expressions. (3,...Ch. 2 - If int x = 10;, int y = 7;, double z = 4.5;, and...Ch. 2 - Prob. 8CPCh. 2 - 9. Suppose that x, y, z, and w are int variables....Ch. 2 - Prob. 10SA
Ch. 2 - Which of the following are valid C++ assignment...Ch. 2 - Write C++ statements that accomplish the...Ch. 2 - Write each of the following as a C++ expression....Ch. 2 - Prob. 14SACh. 2 - Suppose x, y, and z are int variables and wandt...Ch. 2 - 16. Suppose x, y, and z are int variables and x =...Ch. 2 - Suppose a and b are int variables, c is a double...Ch. 2 - 18. Write C++ statements that accomplish the...Ch. 2 - Which of the following are correct C++ statements?...Ch. 2 - Give meaningful identifiers for the following...Ch. 2 - 21. Write C++ statements to do the following....Ch. 2 - Prob. 22SACh. 2 - The following program has syntax errors. Correct...Ch. 2 - Prob. 24SACh. 2 - Prob. 25SACh. 2 - Preprocessor directives begin with which of the...Ch. 2 - 27. Write equivalent compound statements if...Ch. 2 - 28. Write the following compound statements as...Ch. 2 - 29. Suppose a, b, and c are int variables and a =...Ch. 2 - Suppose a, b, and sum are int variables and c is a...Ch. 2 - Prob. 31SACh. 2 - Prob. 32SACh. 2 - Prob. 33SACh. 2 - Prob. 34SACh. 2 - 1. Write a program that produces the following...Ch. 2 - Prob. 2PECh. 2 - Prob. 3PECh. 2 - 4. Repeat Programming Exercise 3 by declaring...Ch. 2 - Prob. 5PECh. 2 - Prob. 6PECh. 2 - 7. Write a program that prompts the user to input...Ch. 2 - Prob. 8PECh. 2 - 9. Write a program that prompts the user to enter...Ch. 2 - 10. Write a program that prompts the user to input...Ch. 2 - 11. Write a program that prompts the capacity, in...Ch. 2 - 12. Write a C++ program that prompts the user to...Ch. 2 - 13. To make a profit, a local store marks up the...Ch. 2 - 14. (Hard drive storage capacity) If you buy a 40...Ch. 2 - 15. Write a program to implement and test the...Ch. 2 - 16. A milk carton can hold 3.78 liters of milk....Ch. 2 - 17. Redo Programming Exercise 16 so that the user...Ch. 2 - Prob. 18PECh. 2 - 19. Write a program that prompts the user to input...Ch. 2 - 20. For each used car a salesperson sells, the...Ch. 2 - 21. Newton's law states that the force, , between...Ch. 2 - 22. One metric ton is approximately 2,205 pounds....Ch. 2 - 23. Cindy uses the services of a brokerage firm to...Ch. 2 - 24. A piece of wire is to be bent in the form of a...Ch. 2 - 25. Repeat Programming Exercise 24, but the wire...Ch. 2 - 26. A room has one door, two windows, and a...Ch. 2 - Prob. 27PECh. 2 - 28. In an elementary school, a mixture of equal...Ch. 2 - 29. A contractor orders, say, 30 cubic yards of...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 10. a. Point Out errors: #include void main() { char arr[8]="Rhombus"; int i; for(i=0;i #include void main() { char *str1="United"; char *str2="Front"; char *str3; str3=strcat(str1,str2); printf("\n %s",str3); [- [- c. Compare Union and Structure.arrow_forwardPROBLEM: Repetition Control Structure (while, do-while) SHOW THE CODES IN ANY JAVA APPLICATION LIKE JCRATOR AND ECLIPSE. OUTPUT SHOULD BE LIKE IN THE TABLE.arrow_forward1) Find the errors in the following codes: int main() { int { Hanging Indent #include ; int a = 1;b = 4; c, d C + = a++; d = 5--; printf("Please enter an inter: "); scanf("%f", num) d = (num = 0? a+b:a+b+c); sum = (a:b:c:d: a+b+c+d); printf("Sum is %d: \n", Sum); Return 0; } 2) Assume a, b, c and n are float variables, and d, e, fand m are integer variables, what is the result of each “printf” function in the following program? Please do not run IDE to get the results.arrow_forward
- CFG: Example 1 • Draw the CFG for the following code: int f(int n){ } int m = n* n; if (n < 0) else return 0; return m;arrow_forwardJAVA CODE ONLY AND PROVIDE OUTPUT SCREENSHOT PLEASEarrow_forward1) Find the errors in the following codes: int main() { } int { Hanging Indent #include ; int a = 1;b = 4; c, d C + = a++; d = 5--; printf("Please enter an inter: "); scanf("%f", num) d = (num = 0? a+b:a+b+c); sum= (a:b:c:d: a+b+c+d); printf("Sum is %d: \n", Sum); Return 0;arrow_forward
- (Numerical) Using the srand() and rand() C++ library functions, fill an array of 1000 floating-point numbers with random numbers that have been scaled to the range 1 to 100. Then determine and display the number of random numbers having values between 1 and 50 and the number having values greater than 50. What do you expect the output counts to be?arrow_forwardThe program in the Programming Example: Fibonacci Number does not check whether the first number entered by the user is less than or equal to the second number and whether both the numbers are non-negative. Also, the program does not check whether the user entered a valid value for the position of the desired number in the Fibonacci sequence. Rewrite that program so that it checks for these things.arrow_forward(Numerical) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters to 0, and then generate a large number of pseudorandom integers between 0 and 9. Each time a 0 occurs, increment the variable you have designated as the zero counter; when a 1 occurs, increment the counter variable that’s keeping count of the 1s that occur; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of the time they occurred.arrow_forward
- (Numerical) Write and test a function that returns the position of the largest and smallest values in an array of double-precision numbers.arrow_forwardWhat a solution with java language please ?arrow_forwardFind the error/s in the following code, highlight and write the correct code on a piece of paper. 1. discr == b*b - 4*a*c; if discr < 0 disp(’Warning: discriminant is negative, roots are imaginary’) else discr =0 disp(’Discriminant is zero, roots are repeated’) elseif disp(’Roots are real’) end 2. n = 5;A = eye(n):for j=2,n for i=1:j-1 A(i,j)=i/j; A[j,i]=i/j; Endendarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Control Structure in Data Structure - Data Structures - Computer Science Class 12; Author: Ekeeda;https://www.youtube.com/watch?v=9FTw2pXLhv4;License: Standard YouTube License, CC-BY