Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 6.3, Problem 28STE
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 >> next;
while (next != ‘\n’)
{ if ((count % 2) == 0)
cout << next;
count++;
cin >> next;
}
If the dialogue begins as follows, what will be the next line of output?
Enter a line of input:
0 1 2 3 4 5 6 7 8 9 10 11
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
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.Example: int x[10], y[10];...for (int i=0; i<10; i++)x[i] = y[i];Answer: 10*sizeof(int)Example: int *x, *y; ...; y = x;Answer: sizeof(int*)
(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));
The code below is for a complete program:
real, dimension(n), allocatable:: ab
do
read(*,*) n
allocate(ab(n))
do i=1, n
c=c+ab(i)
end do
print*, c
end do
end
n should be always positive to run the program properly. To allow the code to return correct outputs, how many errors in the code if any exist where ab should have numeric values?
Question 5 options:
5 to 6 errors
3 to 4 errors
The code will compile and run perfectly
more than 6 errors
1 to 2 errors
Question is expanding on previous written code bellow(program written in C).
(4) Using a loop, extend the program to handle multiple lines of input. Continue until the user enters q to quit. Ex:
Enter input string: Jill, Allen
First word: Jill
Second word: Allen
Enter input string: Golden , Monkey
First word: Golden
Second word: Monkey
Enter input string: Washington, DC
First word: Washington
Second word: DC
Enter input string:
q
Current program to expanded on:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_LIMIT 50
//Function definitionint Commacheck(char *input)
{
int flag = 0;
for(int i = 0; i < strlen(input); i++)
{ //if comma is present in the input entered by user, update the fag to 1.
if(input[i] == ',')
{
flag = 1;
break;
}
}
return flag;
}//Main functionint main(void)
{ //varaiable initialization
char…
Chapter 6 Solutions
Problem Solving with C++ (10th Edition)
Ch. 6.1 - Prob. 1STECh. 6.1 - Prob. 2STECh. 6.1 - Suppose that you are still writing the same...Ch. 6.1 - Prob. 4STECh. 6.1 - Prob. 5STECh. 6.1 - Prob. 6STECh. 6.1 - Suppose bla is an object, dobedo is a member...Ch. 6.1 - Prob. 8STECh. 6.1 - Prob. 9STECh. 6.1 - A program has read half of the lines in a file....
Ch. 6.1 - Prob. 11STECh. 6.2 - Prob. 12STECh. 6.2 - Prob. 13STECh. 6.2 - Prob. 14STECh. 6.2 - What output will be sent to the stuff.dat when the...Ch. 6.2 - Prob. 16STECh. 6.2 - In formatting output, the following flag constants...Ch. 6.2 - Here is a code segment that reads input from...Ch. 6.2 - Prob. 19STECh. 6.2 - Write the definition for a void function called...Ch. 6.2 - (This exercise is for those who have studied the...Ch. 6.3 - Suppose c is a variable of type char. What is the...Ch. 6.3 - Suppose c is a variable of type char. What is the...Ch. 6.3 - Prob. 24STECh. 6.3 - Consider the following code (and assume that it is...Ch. 6.3 - Consider the following code (and assume that it is...Ch. 6.3 - Suppose that the program described in Self-Test...Ch. 6.3 - Consider the following code (and assume that it is...Ch. 6.3 - Prob. 29STECh. 6.3 - Define a function called copyLine that takes one...Ch. 6.3 - Prob. 31STECh. 6.3 - (This exercise is for those who have studied the...Ch. 6.3 - (This exercise is for those who have studied the...Ch. 6.3 - Suppose ins is a file input stream that has been...Ch. 6.3 - Write the definition for a void function called...Ch. 6.3 - Consider the following code (and assume that it is...Ch. 6.3 - Write some C++ code that will read a line of text...Ch. 6 - Write a program that will search a file of numbers...Ch. 6 - Write a program that takes its input from a file...Ch. 6 - a. Compute the median of a data file. The median...Ch. 6 - Write a program that takes its input from a file...Ch. 6 - Write a program that gives and takes advice on...Ch. 6 - Write a program that reads text from one file and...Ch. 6 - Prob. 7PCh. 6 - Write a program to generate personalized junk...Ch. 6 - Write a program to compute numeric grades for a...Ch. 6 - Enhance the program you wrote for Programming...Ch. 6 - Prob. 4PPCh. 6 - Write a program that will correct a C++ program...Ch. 6 - Write a program that allows the user to type in...Ch. 6 - This project is the same as Programming Project 6,...Ch. 6 - This program numbers the lines found in a text...Ch. 6 - Write a program that computes all of the following...Ch. 6 - The text file babynames2012.txt, which is included...Ch. 6 - To complete this problem you must have a computer...Ch. 6 - Write a program that prompts the user to input the...Ch. 6 - The following is an old word puzzle: Name a common...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
A __________ is a predicate that takes two arguments.
Starting Out with C++ from Control Structures to Objects (9th Edition)
Assuming that intNumber is an integer variable, what value will each of the following statements assign to it? ...
Starting Out With Visual Basic (8th Edition)
What is a constructor?
Computer Science: An Overview (12th Edition)
Let a and b denote object modules or static libraries in the current directory, and let a b denote that a depen...
Computer Systems: A Programmer's Perspective (3rd Edition)
Does a static member variable come into existence in memory before, at the same time as, or after any instances...
Starting Out with C++: Early Objects
Write a single pseudocode statement that indicates each of the following: Display the message Enter two numbers...
C How to Program (8th Edition)
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
- Please note this is not Java or C++ Complete the program 'Bcast-Reduce-Assignment.c' to make the program have the output as follows if we run the program using 2 processes. The input sequence is: 0 1 2 3 The output sequence is: 0 2 6 12 This is an MPI program and the code below is partially finished. i am supposed to have input above result in the output above. ////////////////////////////////////////////////////////////////////////////// This is a simple MPI program using MPI_Bcast and MPI_Reduce functions//// Compile: mpicc Bcast-Reduce-Example.c -o Bcast-Reduce-Example// // Run: mpiexec -n <p> ./Bcast-Reduce-Example//// -p: the number of processes/////////////////////////////////////////////////////////////////////////// #include <stdio.h>#include <stdlib.h>#include <mpi.h> int main(void){int my_rank, comm_sz;int i; int Count = 4;int Number[4]; int PartialResult = 0;int Result;…arrow_forward11.3.1: Step counter. A pedometer treats walking 2,000 steps as walking 1 mile. Write a program whose input is the number of steps, and whose output is the miles walked. If the input is 5345, the output is 2.6725. Your program should define and call a function: Function StepsToMiles(integer userSteps) returns float numMiles Need program written in coral languagearrow_forwardUse C++ Write a program that simulates flipping a coin to make decisions. The input is how many decisions are needed, and the output is either heads or tails. Assume the input is a value greater than 0. Ex: If the input is: 3 the output is: heads tails heads For reproducibility needed for auto-grading, seed the program with a value of 2. In a real program, you would seed with the current time. In that case, every program's output would be different, which is what is desired but can't be auto-graded. Note: A common student mistake is to call srand() before each call to rand(). But seeding should only be done once, at the start of the program, after which rand() can be called any number of times. Your program must define and call the following function that returns "heads" or "tails".string HeadsOrTails()arrow_forward
- In C, Assume that the int variables i and j have been declared, and that n has been declared and initialized.Write code that causes a "triangle" of asterisks of size n to be output to the screen. Specifically, n lines should be printed out, the first consisting of a single asterisk, the second consisting of two asterisks, the third consisting of three, etc. The last line should consist of n asterisks. Thus, for example, if n has value 3, the output of your code should be******You should not output any space characters.arrow_forwardQuestion R .Consider the program segment below : #include <stdio.h> void guess (int,int); int main() { int a = 100, b = 200; int c; printf (“a is %d, b is %d\n”, a, b); guess (a, b); printf (“a is %d, b is %d\n”, a, b); return 0; } void guess (int x, int y) { int value; value = x; x = y; y = value; printf (“x is %d, y is %d\n”, x, y); } A. Identify the function call, the function header and the function prototype. B. What is the data type of x? C. Determine the output. Full explain this question and text typing work only We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this linearrow_forwardComputer Science Write a program that processes a data sequence according to the following specifications: The sequence has three kinds of positive numbers: red, black and white. Each red number is preceded by the letter r, each black number is preceded by the letter b and each white number is preceded by the letter w. The number 0 indicates the end of data. If a number is preceded by any character other than r, b or w, the number is ignored. For instance, if the input to the program is: r 23 b 15 b 11 w 17 c 13 r 19 b 0, then we have two red numbers, 23 and 19, two black numbers 15 and 11, and one white number, 17. The number 13 is ignored. (The terminating 0 is also a black number but it is not processed.) The program produces the following output: The sum of red numbers is 42The sum of black numbers is 26The sum of white numbers is 17 Assume that input is from the keyboard and is in the prescribed format. (a). In 2-3 sentences, describe your strategy for solving this…arrow_forward
- in javascript please create a function that does the following and is named as such please don't copy and paste the incorrect answer sequence( start, step ) This function takes two numeric inputs, start and step, and returns a function of no inputs. The ith invocation of the resulting function will generate the value: start + step * i. The first invocation is said to be the 0th. Examples var x = sequence( 3, 15 ) [ x(), x(), x() ] => [ 3, 18, 33 ] var y = sequence( 28, -5 ) [ y(), y(), y() ] => [ 28, 23, 18 ]arrow_forwardAssume the following declarations and initializations (MIN, MAX, num) are made justbefore each sub-question 1 to 15 (i.e., assume these initializations are in effect at thebeginning of each problem). What is the output each code? final int MIN = 10, MAX = 20;int num = 15; 8. do {num = num + 1;if (num * 2 > MAX + num)System.out.print(num + “ “);} while (num <= MAX); 9. for (int value = 0; value >= 7; value++)System.out.print(value + “ “); 10. for (int value = 7; value < 0; value--)System.out.print(value + “ “); 11. for (int value = 1; value >= 20; value+=4)System.out.print(value + “ “);arrow_forward5.19 In Python Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 10 miles, 50 miles, and 400 miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows:print('{:.2f}'.format(your_value)) Ex: If the input is: 20.0 3.1599 the output is: 1.58 7.90 63.20 Your program must define and call the following driving_cost() function. Given input parameters driven_miles, miles_per_gallon, and dollars_per_gallon, the function returns the dollar cost to drive those miles. Ex: If the function is called with: 50 20.0 3.1599 the function returns: 7.89975 def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon) Your program should call the function three times to determine the gas cost for 10 miles, 50 miles, and 400 miles.arrow_forward
- Write a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 3 8 the output is: 8 3 Your program must define and call the following function. swap_values() returns the two values in swapped order.def swap_values(user_val1, user_val2) I get all tests passed except one.: the one in the bold. It puts parentheses around the answer instead of what they want for output. 0 / 2 Output differs. See highlights below. Input 4 5 Your output (5, 4) Expected output 5 4 2: Unit testkeyboard_arrow_up 2 / 2 swap_values(-1, 10) Your output swap_values(-1, 10) correctly returned 10 -1 3: Unit testkeyboard_arrow_up 3 / 3 swap_values(9, 0) Your output swap_values(9, 0) correctly returned 0 9 4: Unit testkeyboard_arrow_up 3 / 3 swap_values(11, 11) Your output swap_values(11, 11) correctly returned 11 11arrow_forwardCode should be in Python, please Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string. Ex: If the input is: 6 the output is: 110 Your program must define and call the following two functions. The function integer_to_reverse_binary() should return a string of 1's and 0's representing the integer in binary (in reverse). The function reverse_string() should return a string representing the input string in reverse.def integer_to_reverse_binary(integer_value)def reverse_string(input_string)arrow_forwardModify the following C code to get the given output: #include <pthread.h> #include <semaphore.h> #include <stdio.h> /* This program provides a possible solution using mutex and semaphore. use 5 Fsrmers and 5 ShopOwner to demonstrate the solution. */ #define MaxCrops 5 // Maximum crops a Farmer can produce or a Shpoowner can take #define warehouseSize 5 // Size of the warehouse sem_t empty; sem_t full; int in = 0; int out = 0; char crops[warehouseSize]={'R','W','P','S','M'};//indicatig room for different crops char warehouse[warehouseSize]={'N','N','N','N','N'};//initially all the room is empty pthread_mutex_t mutex; void *Farmer(void *far) { /* 1.Farmer harvest crops and put them in perticular room. For example, room 0 for Rice(R). 2.use mutex and semaphore for critical section. 3.print which farmer is keeping which crops in which room inside the critical section. 4.print the whole warehouse buffer outside of the critical section */ }…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Introduction to Operators in C; Author: Neso Academy;https://www.youtube.com/watch?v=50Pb27JoUrw;License: Standard YouTube License, CC-BY