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++ (9th 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)
- (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_forwardC Language - Write a program that takes in three integers and outputs the largest value. If the input integers are the same, output the integers' value.arrow_forwardGiven x 0, у 3 1, count 3. After the following code is executed, count ++; y=x; if (x < 0) count--; else count++; the value of x isarrow_forward
- #include <stdio.h>int main(){int d;int s[20],i, r, p, lg=0,m;char c;printf("Enter number of salesman(max 20): ");scanf("%d", &d);for(i=0; i<d; i++){ printf("\n salesman %d sales: ");scanf("%d", &s[i]);}for(i=0; i<d; i++){for(r=i+1; j<d; r++){if(s[i] > s[r]){p= s[i];s[i] = s[r];s[j] = p;}}}printf("\nsalesman lowest to highest: ");for(i=0; i<d; i++){printf("%d\t", s[i]);}for(i=0;i<m;i++){printf("\n highest sales: %d ",lg);if(lg<=s[i])lg=s[i];break;}getch();} >>> the upper part output should be like this enter number of salesman (max 20): 5 salesman 1 500 salesman 2 300 salesman 3 1000 salesman 4 200 salesman 5 1000 in the lower part the lowest to highest the output should become like this salesman 4 200 salesman 2 300 salesman 1 500 salesman 3 1000 salesman 5 1000 highest total sales : 2000arrow_forwardCFG: 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_forward#include <stdio.h> int main(){ int a; /* for loop execution */ for ( a = 1; a <= 100; a++){ printf("%d\n",a * a); } return 0; } write a code using while loop that will provide the same output as the code given above.arrow_forwardFind an incorrect line in the following code segment: void swap(int *x, int *y) { int t = *x; *x = *y; *y = t;}....int a = 2, b = 3;swap(*a, *b);arrow_forwardLucky Customer Code in C Languagearrow_forward1. a. Are Count and sum the same? yes or no, why? { int sum = 0; for ( int count = 0; count < 10; count++ ) { System.out.print( count + " " ); sum = sum+count; } } b. { int sum = 0; for ( int count = 0; count < 10; count++ ) { System.out.print( count + " " ); sum = sum+count; } System.out.println("\nAfter the loop count is: " + count ); } c. What is printed, why? class FindIt { private int sum; public FindIt( int sum ) { this.sum = sum; } public void increment( int inc ) { sum = sum + inc; System.out.println("FindIt sum: " + sum ); } } public class MainClass { public static void main ( String[] args) { int sum = 99; FindIt findObj = new FindIt( 34 ); findObj.increment( 6 ); System.out.println("sum: " + sum ); } }arrow_forwardGiven initial values of x= and a code : 2, y = 1 and count 2. count+=y; if (count 3 ) X--; else x++; Give the value of variables after the above code is executed.arrow_forwardHomework 5 CMP 167: Programming Methods I Lehman College, City University of New York Homework 5-1 I Write a program with a loop that iterates as long as an int variable called num is less or equal to 50. Num must be initialized with a value of 1 and incremented by 1 with each iteration. Each iteration of the loop must print all appropriate sentences for that number according to the following 1. If num is odd, output: num is an odd number 2. If num is even, output: num is an even number output: num is divisible by 2 3. If num is divisible by 2, 4. If num is divisible by 5, output: num is divisible by 5 5. If num is divisible by 8, output: num is divisible by 8 6. If num is divisible by 11, output: num is divisible by 11 Please note that your class should be named FirstLoop.arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr