Concept explainers
Consider the following code (and assume that it is embedded in a complete and correct
char next;
int count = 0;
cout <<“Enter a line of input:\n”;
cin. get(next);
while (next != ‘\n’)
{
if ((count % 2) == 0) True if count is even
cout << next;
count ++;
cin.get(next) ;
}
If the dialogue begins as follows, what will be the next line of output?
Enter a line of input:
abcdef gh
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Starting Out with Programming Logic and Design (4th Edition)
Concepts of Programming Languages (11th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
Artificial Intelligence: A Modern Approach
Web Development and Design Foundations with HTML5 (8th Edition)
C++ How to Program (10th Edition)
- In each of the following code snippets, data is copied from x to y. How many bytes of data arecopied? The answer should be a C expression. (e) int x=10, y=x;(f) int x[10]; int *y = x;(g) int x[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; void f(int y[5]) { ... } int main() { f(x); }(h) int x[10], y[10]; ... memcpy(y, x, 5*sizeof(int));arrow_forward4.16 In Python, Write a program whose input is two integers. Output the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 30 the output is: -15 -5 5 15 25 Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than the first. For coding simplicity, output a space after every integer, including the last.arrow_forward4.16 In Python, Write a program whose input is two integers. Output the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 30 the output is: -15 -5 5 15 25 (with the end starting a new line.) Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than the first. For coding simplicity, output a space after every integer, including the last. creating a new line at the end. (ex: 5 4 3 2 1 )arrow_forward
- Statistics are often calculated with varying amounts of input data. Write a program that takes any number of integers as input, and outputs the average and max. Ex: If the input is: 15 20 0 5 the output is: 10 20 My code: data = input("")count = 0total = 0max = -99999 for val in data:total += int(val)count += 1if int(val) > max:max = int(val)avg = total/count print(avg)print(max) *When this code did produce an output average was output as 17.5 and not 10. I made adjustments to try to get 10 and now I am getting errors.arrow_forwardConsider the following code: tyepdef struct { char grade; float score; } student; void f() { student a = { .grade = 'C', .score = 75.0 }; student b = { .grade = 'C', .score = 75.0 }; if (!memcmp(&a, &b, sizeof(student))) { printf("Same"); } else { printf("Different"); } } What could cause the program to print "Different"? A. memcmp examines the bytes in little endian B. memcmp returns true if contents of the memory are the same; remove the ! C. memcmp always returns a non-zero value D. The compiler may have included padding in the structs E. The compiler may have arranged the fields of the two structs differentlyarrow_forwardGiven the following program segment: int first = 3; int second = 4; int j; for ( j = 1; j <= first; j++) { cout << second * j <<endl; second= second + (j - 1); } cout << endl; Your task is to write a while loop and a do ... while loop which will produce the same output.arrow_forward
- Program in C. Solve the problems below. #include <stdio.h>int par_ou_impar(int n){return n%2==0?1:0;}int main() {int n;scanf("%d",&n);if(par_ou_impar(n)==0) printf("impar");else printf("par");return 0;} __tester__.c:23:5: error: redefinition of ‘main’ int main() { ^~~~ __tester__.c:13:5: note: previous definition of ‘main’ was here int main() { ^~~~arrow_forwardPerform a desk check of the following code by walking thru the program and executing it like a computer would. A complete desk check must include: 1. An evaluation of all decision logic indicating the line number of the decision replacing variable names with their values at the time of the evaluation and then indicating if it was true of false.2. A PseudoMonitor™ that shows the output3. A memory map/table that tracks all variable values. Be sure to have three separate areas (three sheets of paper if needed) to document the above. State whether the algorithm represented by the code produces valid results given the obvious objective of the program. If not, explain why not. Even if it works with the given data set, does it contain potential hazards? Explain. Can you optimize the code in any way? You may not execute every line of code depending on the logic of the code and program inputs. Use the following incoming data for your program desk check. INCOMING DATA 3 6…arrow_forwardConsider the following code snippet, and choose the best statement below: int cards[4]; for (int i = 0; i<=4; i++) cin >> cards[i]; a) This code will not compile b) This code will compile and run, but will write to out of bounds memory c) This code will compile and run, but will read from out of bounds memory d) This code will compile and runarrow_forward
- Write a program that reads integers between 1 and 100 and counts the occurrences of each. Assume the input ends with 0. Write a program that reads integers between 1 and 100 and counts the occurrences of each. Assume the input ends with 0. Here is a sample run of the program: Enter integers from 1-100 (input 0 value to end inputs): 2 5 6 5 4 3 23 43 2 02 occurred 2 times3 occurred 1 time4 occurred 1 time5 occurred 2 times6 occurred 1 time23 occurred 1 time43 occurred 1 timearrow_forward. Suppose that the input is 0 8 12 50 7 13 -1. What is the output of the following code? int num, sum, count; cin >> sum; cin >> count; cin >> num; while (count <= 4) { sum = sum + num; count++; cin >> num; } cout << "Sum = " << sum << endl;arrow_forwardWrite a program that take 5 digit number as an input from the user and perform the following tasks:1. Split a number into digits.2. Find the sum of the all the digits in the number.3. Find the product of the all the digits in the number.4. Find maximum number with in the number along with position.5. Printing the digits in the reverse order.Note: Make user defined functions to perform each task.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education