Problem Solving with C++, Student Value Edition Plus MyLab Programming with Pearson eText - Access Card Package (10th Edition)
10th Edition
ISBN: 9780134756424
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 2.3, Problem 16STE
Explanation of Solution
Program:
//Header file
#include <iostream>
//For standard input and output
using namespace std;
//Main function
int main()
{
//Assign the variables "a" to character 'b'
char a = 'b';
// Assign the variables "b" to character 'c'
char b = 'c';
//Set a variables "a" to "c"
char c = a;
//Display the given result
cout << a << b << c << 'c';
return 0;
}
Explanation:
The given code is used to display the character in the given initialization.
- Define main function.
- First, assign the “char” variable “a” to character ‘b’.
- Assign the “char” variable “b” to character ‘c’...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
What is the output of the following C++ program segment? Assume all variables are properly declared. for (j = 0; j < 8; j11){cout << j * 25 << " - ";if (j != 7)cout << (j + 1) * 25 - 1 << endl;elsecout << (j + 1) * 25 << endl;}
In C, Given a char variable c that has already been declared, write some code that repeatedly reads a value from standard input into c until at last a 'Y' or 'y' or 'N' or 'n' has been entered.
Consider 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;
Chapter 2 Solutions
Problem Solving with C++, Student Value Edition Plus MyLab Programming with Pearson eText - Access Card Package (10th Edition)
Ch. 2.1 - Give the declaration for two variables called feet...Ch. 2.1 - Give the declaration for two variables called...Ch. 2.1 - Give a C++ statement that will change the value of...Ch. 2.1 - Give a C++ statement that will increase the value...Ch. 2.1 - Give a C++ statement that will change the value of...Ch. 2.1 - Prob. 6STECh. 2.1 - Prob. 7STECh. 2.2 - Give an output statement that will produce the...Ch. 2.2 - Give an input statement that will fill the...Ch. 2.2 - Prob. 10STE
Ch. 2.2 - Write a complete C++ program that writes the...Ch. 2.2 - Write a complete C++ program that reads in two...Ch. 2.2 - Prob. 13STECh. 2.2 - Write a short program that declares and...Ch. 2.3 - Convert each of the following mathematical...Ch. 2.3 - Prob. 16STECh. 2.3 - What is the output of the following program lines...Ch. 2.3 - Write a complete C++ program that reads two whole...Ch. 2.3 - Given the following fragment that purports to...Ch. 2.3 - What is the output of the following program lines...Ch. 2.4 - Write an if-else statement that outputs the word...Ch. 2.4 - Suppose savings and expenses are variables of type...Ch. 2.4 - Write an if-else statement that outputs the word...Ch. 2.4 - Write an if-else statement that outputs the word...Ch. 2.4 - Consider a quadratic expression, say x2 x 2...Ch. 2.4 - Consider the quadratic expression x2 4x + 3...Ch. 2.4 - What is the output of the following cout...Ch. 2.4 - What is the output produced by the following (when...Ch. 2.4 - What output would be produced in the previous...Ch. 2.4 - What is the output produced by the following (when...Ch. 2.4 - What is the output produced by the following (when...Ch. 2.4 - What is the most important difference between a...Ch. 2.4 - What is the output produced by the following (when...Ch. 2.4 - Write a complete C++ program that outputs the...Ch. 2.5 - The following if-else statement will compile and...Ch. 2.5 - Prob. 36STECh. 2.5 - Write a complete C++ program that asks the user...Ch. 2 - A metric ton is 35,273.92 ounces. Write a program...Ch. 2 - The Babylonian algorithm to compute the square...Ch. 2 - Many treadmills output the speed of the treadmill...Ch. 2 - Write a program that plays the game of Mad Lib....Ch. 2 - The following is a short program that computes the...Ch. 2 - A government research lab has concluded that an...Ch. 2 - Workers at a particular company have won a 7.6%...Ch. 2 - Modify your program from Programming Project 2 so...Ch. 2 - Negotiating a consumer loan is not always...Ch. 2 - Write a program that determines whether a meeting...Ch. 2 - Prob. 6PPCh. 2 - It is difficult to make a budget that spans...Ch. 2 - You have just purchased a stereo system that cost...Ch. 2 - Write a program that reads in ten whole numbers...Ch. 2 - Modify your program from Programming Project 9 so...Ch. 2 - Sound travels through air as a result of...Ch. 2 - Prob. 12PPCh. 2 - The HarrisBenedict equation estimates the number...Ch. 2 - Write a program that calculates the total grade...Ch. 2 - It is important to consider the effect of thermal...Ch. 2 - Prob. 16PP
Knowledge Booster
Similar questions
- what is the output of the following code and correct the mistakes if any ( this code to find the factorial or the number in string X : X DB 2,3,5,6 Y DW 4 DUP (?) Mov BL,X CALL FACT Mov Y,Ax FACT PROC Mov AL,1 L: MUL BL DEC BL JNZ L RET FACT ENDParrow_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;} a. What is the output of the following C++ statements? i. cout << secret(18, 4) << endl; ii. cout << secret(-10, 20) << endl;b. What does the function secret do?arrow_forwardplease provide the answers to the points in this variable trace Trace through the program below. Indicate value of each of the variables or parameters at the indicated points in the program. Enter 'U' if the variable or parameter is undefined or does not exist at that point. #include <iostream.h>void test (int, int &);int y;void main (void){int x;x = 5; y = 6; // point #1 test (x, y); // point #3}void test (int a, int &b){int c; y = 1; a = 3; b = 9; c = 5; // point #2} Point #1, Variable x Point #1, Variable y Point #1, Variable a Point #1, Variable b Point #1, Variable c Point #2, Variable x Point #2, Variable y Point #2, Variable a Point #2, Variable b Point #2, Variable c Point #3, Variable x Point #3, Variable y Point #3, Variable a Point #3, Variable b Point #3, Variable carrow_forward
- Complete the following questions about different types of variables:i. Check the last digit of your id number(123456789). If it is even or 0, fill the gap in (A)with the word global (i.e., static global), otherwise, fill it with local (i.e., static local).Then, complete Table I. ii. In a multi-source program, there is a fileA.c that contains variables and functions,and a fileB.c that contains the main function, as well as usage of some of theresources found in fileA.c. Explain:a) fileA.c has a global variable called my_variable, that should only beaccessed within the file. I.e., no other files should be able to access thatvariable.How should my_variable be declared inside of the file, in order to guaranteethis functionality? b) fileA.c also has a global variable called my_shared_variable, which canand should be accessible from other files, including fileB.c.How should my_shared_variable be declared in order to allow thisfunctionality?Note for item ii): You also need to state in a…arrow_forwardIn my C++ program, I am trying to write code that will check command line arguments for "-amount" and if the next argument is a double, and if this is true, to print out the double value. So far I have the code: int main(int argc, char* argv[]){cout << "1. CheckAmount program that checks commandline arguments:" << endl;for (int i = 1; i < argc; i++){if (strcmp(argv[i], "-amount")){int x = stod(argv[i + 1]);if (isdigit(x) == true){cout << argv[i + 1] << endl;}elsecout << -1 << endl;}} The debugger gives me an error because an exception is thrown with the conversion line of code. I do not yet know how to do exception handling, is there another way to check if the command line argument is a double?arrow_forwardConsider the following program in C-like syntax:void f1();void f2();int main(){int x, y;...}int f1()int a, b, x;...}int f2(){int b, c, x, y;...} If the programming language uses dynamic scoping, what are the variables that arevisible in the last function in the following call sequences? Give not only the names ofthe variables, but also where they are declared.(a) main → f1 → f2(b) main → f2 → f1arrow_forward
- What is the output of the following program segment? int count = 0;while (++count < 5)cout << count + 1 << " ";cout << endl;arrow_forwardPlease read the question to the very end. Below is an example of a code that we need to reprogram in C++ #include <iostream>const char* filename = "Humans.dat";struct Human {char name[20];int phone;};void my_scanf(Human *s, unsigned short int n) {printf("Enter name %hu >", n+1); scanf("%25s", s->name);printf("Enter phone >"); scanf("%i", &s->phone);}void my_printf(Human *s, unsigned short int n) {for (unsigned short int i = 0; i < n; i++)printf("%i. Name: %s, phone: %i\n", i+1, s[i].name, s[i].phone);}void read_from_user_and_save_to_file() {unsigned short int m; printf("Enter count of Humans >"); scanf("%hu", &m);Human* AllHumans = new Human[m];for (unsigned short int i = 0; i < m; i++) my_scanf(&AllHumans[i], i);my_printf(AllHumans, m);FILE * fp = fopen(filename, "wb");fwrite(AllHumans, sizeof(Human), m, fp); fclose(fp);}void read_from_file_and_show_to_user() {FILE * fp = fopen(filename, "rb");fseek(fp, 0, SEEK_END);unsigned int fsize =…arrow_forwardEach function should accept two integer parameters indicating the minimum and maximum X value to be plotted. The functions should have no return values. Create class-level constants for things we might wish to change later, e.g., a char called PLOT_CHAR that holds an “x” (per samples below), another char called FILL_CHAR that holds an unobtrusive character like ASCII 183, generated with a cast, e.g., (char)183. JAVA PLEASE THOSE ARE NOT PERIODS OR DOTS. USE (System.out.print((Char)183); for (.) Please DON'T USE Loops(while);, if, Arrays, lists, or other data structures, objects, libraries, or methods. Sideways Ploty = 20sin(.5x)+20 where -11<=x<=11 ··································x ·······································x ·······································x ···································x ···························x ·················x········x·xx···x··········x····················x ·····························x ····································x…arrow_forward
- My prompt for my C++ problem is to write a program that accepts command line arguments and to print out true is the first character of the first argument is the same of the last character of the last argument. Otherwise it prints out false. So far I have the code: #include <iostream> #include <string> using namespace std; int main(int argc, char * argv[]){ bool check;for(int count=1; count < argc; count++) { //cout << argv[count] << endl; if(argv[count] ){ }} //cout << "Is the first character of your first argument the same as the last character of your last argument? ";//cout << boolalpha << check << endl;return 0;} However, I am unsure on how to check the characters in argument. I am assuming that I would create a loop of some fashion that would run through each character in each string argument, but how do I check this if this would mean checking the string array locations within the pointer array ?arrow_forwardHello, I was wanting to see if the code for this problem could be done by detecting the ranges implicitly by avoiding the && (AND) operatorarrow_forward1-int fx(char &x) is a function with parameter passed by value(False/True) 2-int fx(char x) is a function with int return value(False/True) 3-void fx(char ch) is a function with no return value(False/True) 4-char fx( int x) is a function with int return value(False/True)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 LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr