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 25STE
Consider the following code (and assume that it is embedded in a complete and correct
char c1, c2, c3, c4;
cout << “Enter a line of input:\n”;
cin.get(c1);
cin.get(c2);
cin.get(c3);
cin.get(c4);
cout << c1<< c2 << c3 << c4 << “END OF OUTPUT”;
If the dialogue begins as follows, what will be the next line of output?
Enter a line of input:
a b c d e f g
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
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.
Computer 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…
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));
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
Population Write a program that will predict the size of a population of organisms. The program should ask for ...
Starting Out with Java: Early Objects (6th Edition)
For each of the following activities, give a PEAS description of the task environment and characterize it in te...
Artificial Intelligence: A Modern Approach
Write SQL queries to answer the following questions: Which students are enrolled in Database and Networking? (H...
Modern Database Management
What is wrong with the following while statement? 1 while (z = 0) { 2 sum += z; 3 }
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
What message will the following program display if the user enters 5? What if the user enters 10? What if the u...
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
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
- Consider the below code: What would the output if dynamic scoping is used. Consider that execution of the code starts from main() function. #include <stdio.h> void main() { int x =3; A(x); B(x); C(x); } void A(int x) { printf("%d",x); } void B(int x) { int x =1; A(x); } void C(int x) { int x =2; B(x); }arrow_forwardWhat is the output assuming dynamic scoping and static scoping! Give answers for both dynamic and static! #include <iostream> using namespace std; int total = 5; int c = 3; int fun1(int); int fun2(int); int main() { int x = 2; int y = 8; cout << " variables x y and c have values: " << x <<" " << y << " " << c << endl; cout << "main: fun1(x) = " << fun1(x) << endl; cout << " After Call to fun1(x) variables x y and c have values: " << x <<" " << y << " " << c << endl; return 0; } int fun1(int a) { int b = 6; int c = 3; b = total + c + a; cout << "in fun1: b= " << b << endl; cout << "in fun 1 after call to fun2(total) the return value is " << fun2(total) << endl; return (b); } int fun2(int w) { c = c * 2; total = total + w + c; cout << "in fun2: total= " << total << endl; return(c); }arrow_forwardWhen a variable is stored in memory, it is associated with an address. To obtain the address of avariable, the & operator can be used. For example, &a gets the memory address of variable a.Let's try some examples.Write a C program addressOfScalar.c by inserting the code below in the main function. 1 // intialize a char variable, print its address and the next address2 char charvar = 'a';3 printf("address of charvar = %p\n", (void *)(&charvar));4 printf("address of charvar - 1 = %p\n", (void *)(&charvar - 1));5 printf("address of charvar + 1 = %p\n", (void *)(&charvar + 1));67 // intialize an int variable, print its address and the next address8 double doublevar = 1.0;9 printf("address of doublevar = %p\n", (void *)(&doublevar));10 printf("address of doublevar - 1 = %p\n", (void *)(&doublevar - 1));11 printf("address of doublevar + 1 = %p\n", (void *)(&doublevar + 1)); Questions:1) Run the C program, attach a screenshot of the output in the answer…arrow_forward
- Assume that nextWord is a String variable that has been given a String value consisting entirely of letters. Write some Java code that outputs the message "First half of the alphabet", provided nextWord precedes "N" in alphabetic ordering. If nextWord does not precede "N" in alphabetic ordering, the code should output "Second half of the alphabet". (Note that "N" uses double quotes to produce a String value, as opposed to using single quotes to produce a char value.)arrow_forwardMy question: I don't understand why the last output has two letters inside. Can you please fix my code? Write a function `mostFrequentLetter(string)` that takes a string as an argument and returns the character that appears the most often. In case of a tie, you may return any of the characters. The string will have at least one character. Examples: console.log(mostFrequentLetter("apple")); // "p" console.log(mostFrequentLetter("banana")); // "a" console.log(mostFrequentLetter("What about a longer string?")); // " " My code: function countChar(string) { letcountChar = {}; for (leti = 0; i < string.length; i++) { letchar = string[i];//the future key elements if (charincountChar){//create keys countChar[char]++;//create values }else { countChar[char] = 1;//create values } } returncountChar; } function mostFrequentLetter(string) { letmaxCount = countChar(string); letnewArr = Object.entries(maxCount); letmax = newArr[0][1]; letresult = []; for (leti = 0; i < newArr.length;…arrow_forwardConsider the following function: int secret(int m, int n) { int temp = n; for (int i = 1; i < abs(m); i++) temp = temp + n; if (m < 0) temp = -temp; return temp; } What is the output of the following C++ statements? i.cout << secret(5, 4) << endl; ii.cout << secret(-3, 20) << endl;arrow_forward
- Please modify the C++ data structure program below to detect and display multiple candidates with the same number of votes: multiple winners, multiple candidates with the second highest number of votes, multiple candidates with the third highest number of votes, and so on. Please have output show first, second, third and fourth place winners asked in instructions below. The candidate names are attacked. Please provide screen shot of multiple candidates with the same number of votes. Suppose the candidates are A, B, C, D, E, F, G and H and their votes are: A 100 B 200 C 200 D 400 E 100 F 400 G 300 H 300 Then your program should display, A Fourth Place B Third Place C Third Place D First Place E Fourth Place F First Place G Second Place H Second Place votes.txt A = Johnson B = Miller C = Robinson D = Duffy E = Asthon F = Sampson G = Adams H = Williams My code to be modified according to instruction #include <array> #include <cassert> #include…arrow_forwardQuestion 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…arrow_forwardWrite a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 3 8 Output: 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) My Code: def swap_values(user_val1, user_val2):temp = user_val1user_val1 = user_val2user_val2 = tempreturn user_val1, user_val2 if __name__ == '__main__': user_val1 = int(input())user_val2 = int(input()) print(swap_values(user_val1, user_val2)) However the output is (8, 3) which is giving me incorrect due to formating, the output needs to be 8 3 without parantheses and comma.arrow_forward
- 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_forwardUse c++ Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. Ex: If the input is: 7 15 3 the output is: largest: 15 smallest: 3 Your program must define and call the following two functions. The LargestNumber function should return the largest number of the three input values. The SmallestNumber function should return the smallest number of the three input values.int LargestNumber(int num1, int num2, int num3)int SmallestNumber(int num1, int num2, int num3)arrow_forwardWrite output of the following c++ code by completing it with explanation of all iterations Need explanation of code line by line how it will execute. Code #include <iostream> Using namespace std; int fun1(int); int fun(float); int fun1(int n){ if(n<=1) return 1; else return n*fun(n-1); } int fun(float n){ if(n<=1) return 1; else return n*fun(n-1); } int main(){ int n=5; cout<<fun1(n); cout<<fun(4.3); return 0; }arrow_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 Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Introduction to Operators in C; Author: Neso Academy;https://www.youtube.com/watch?v=50Pb27JoUrw;License: Standard YouTube License, CC-BY