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_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_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_forward
- #include int k=0; int f(int t) { k += t; heturn k; } void main() { int i, result=1; for(i = 1;i <= 3;i++) result = f(i); printf("%d\n", result); } A 3 B C) 1 D 123arrow_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_forwardQuestion 1: Please develop a program. The program shows a O(n^2) time complexity. You may design nested loops. When you input a number, the output should be how many times of the loops. For example, if your input is 10, the number of loops should be 100 times, 200 times, 300 times, etc. The number of loops do not have to be an accurate number. Question 2: Please develop a program. The program shows a O(nlgn) time complexity. You may design nested loops. When you input a number, the output should be how many times of the loops. For example, if your input is 10, the number of loops should be 30 times, 60 times, etc. The number of loops do not have to be an accurate number.arrow_forward
- Homework 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_forwardProgramming in language Carrow_forward#include<stdio.h> #include<conio.h> int mutex=1,full=0,empty=1,x=0; main() { int n; void producer(); void consumer(); int wait(int); int(signal); printf("\n1. Producer \n2. Consumer \n,3. Exit \n"); while(1) { printf("\n Enter the choice:"); scanf("%d", &n); switch(n); { case-1: if((mutex==1)&&(empty!=0)) producer(); else printf("Nuffer is full"); break; case-2: if((mutex==1)&&(full!=0)) consumer(); else print("Buffer is empty"); break; case-3: exit(0); break; } } } int wait(int s) {return(--s); } int signal(int s) { return(++s); } void producer() { mutex = wait(mutex); full = signal(full); empty=wait(empty); x++; printf("\n Producer produces the item %d",x); mutex= signal(mutex); } void consume() { mutex = wait(mutex); full = wait(full); empty = signal(empty); printf("\n Consumer consumes item %d",x); x--; mutex = signal(mutex); } CONVERT THIS C LANGUAGE CODE IN BASH SCRIPT THANKYOUarrow_forward
- Q1-Given below is an example of an unstructured program containing an infinite loop and statements like break/continue. void main() (int a, b, I; scanf("%d %d", &a, &b) 1 = -1; while (1) } if (b 1). (b) Convert the above program into an equivalent structured program (i.e. without using break/continue and infinite loop).arrow_forwardDO NOT COPY FROM OTHER WEBSITES Correct and Detailed answer will be Upvoted else downvoted. Thank you!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_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr