Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 6.15, Problem 6.24CP
What is the output of the following
#include <iostream>
#include <cstdlib>
using namespace std;
void showVals(double, double);
int main()
{
double x = 1.2, y = 4.5;
showVals(x, y);
return 0;
}
void showVals(double p1, double p2)
{
cout ≪ p1 ≪ endl;
exi t(0);
cout ≪ p2 ≪ endl;
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
C++ programming
2. What is the output of the following program (when embedded in a complete program)?
void Fun( int& x, int y, int& z);
int main( )
{
int a, b, c;
a = 10;
b = 20;
c = 30;
Fun(a, b, c);
cout << a << " " << b << " " << c << endl;
return 0;
}
void Fun( int& x, int y, int& z)
{
cout << x << " " << y << " " << z << endl;
x = 1;
y = 2;
z = 3;
}
In C programming, if the return type of a function is Void how can you implement assert statements?
For example, Void ceasar(int n, char*x);
//if char = c and n = 3 output == f
how do i use assert statements as this does not work assert (caesar(3,c)==f);
Consider the following obfuscated and confusing program code below.
#include <iostream> using namespace std; int fib(int); int main() { cout << "Enter an index for the Fibonacci number: "; int index; cin >> index; cout << "Fibonacci number at index " << index << " is " << fib(index) << endl; return 0; } int fib(int index) { if (index == 0) return 0; else if (index == 1) return 1; else return fib(index - 1) + fib(index - 2); }
Create a C++ Builder Console Project and copy/paste the above code into the .cpp file of the project.
Run the project... it should run fine.
Now, REFORMAT the code to demonstrate you know Software Engineering principles in making code readable and understandable. FOLLOW the exmples that are given in the textbook and the learning activities. ADD COMMENTS to document what the program/code does. You will be expected to format your code throughout this course using proper indentations and placement of curly braces. STUDY…
Chapter 6 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Ch. 6.2 - Is the following a function header or a function...Ch. 6.2 - Is the following a function header or a function...Ch. 6.2 - What will the output of the following program be...Ch. 6.2 - The following program skeleton determines whether...Ch. 6.6 - Indicate which of the following is the function...Ch. 6.6 - Write a function named timesTen. The function...Ch. 6.6 - Write a function prototype for the timesTen...Ch. 6.6 - Prob. 6.8CPCh. 6.6 - What is the output of the following program?...Ch. 6.6 - The following program skeleton asks for the number...
Ch. 6.9 - How many return values may a function have?Ch. 6.9 - Write a header for a function named distance. The...Ch. 6.9 - Write a header for a function named days. The...Ch. 6.9 - Write a header for a function named getKey. The...Ch. 6.9 - Write a header for a function named lightYears....Ch. 6.11 - What is the difference between a static local...Ch. 6.11 - Prob. 6.17CPCh. 6.11 - Prob. 6.18CPCh. 6.13 - Prob. 6.19CPCh. 6.13 - Write the prototype and header for a function...Ch. 6.13 - Write the prototype and header for a function...Ch. 6.13 - What is the output of the following program?...Ch. 6.13 - The following program asks the user to enter two...Ch. 6.15 - What is the output of the following program?...Ch. 6.15 - What is the output of the following program?...Ch. 6 - Why do local variables lose their values between...Ch. 6 - What is the difference between an argument and a...Ch. 6 - Where do you define parameter variables?Ch. 6 - If you are writing a function that accepts an...Ch. 6 - When a function accepts multiple arguments, does...Ch. 6 - How do you return a value from a function?Ch. 6 - What is the advantage of breaking your...Ch. 6 - How would a static local variable be useful?Ch. 6 - Give an example where passing an argument by...Ch. 6 - The_______ is the part of a function definition...Ch. 6 - If a function doesnt return a value, the word...Ch. 6 - Either a functions _______ or its _______ must...Ch. 6 - Values that are sent into a function are called...Ch. 6 - Special variables that hold copies of function...Ch. 6 - When only a copy of an argument is passed to a...Ch. 6 - A(n) _______ eliminates the need to place a...Ch. 6 - A(n) _______ variable is defined inside a function...Ch. 6 - _______ variables are defined outside all...Ch. 6 - _______ variables provide an easy way to share...Ch. 6 - Unless you explicitly initialize global variables,...Ch. 6 - If a function has a local variable with the same...Ch. 6 - _______ local variables retain their value between...Ch. 6 - The _______ statement causes a function to end...Ch. 6 - _______ arguments are passed to parameters...Ch. 6 - When a function uses a mixture of parameters with...Ch. 6 - Prob. 26RQECh. 6 - When used as parameters, _______ variables allow a...Ch. 6 - Reference variables are defined like regular...Ch. 6 - Reference variables allow arguments to be passed...Ch. 6 - The _______ function causes a program to...Ch. 6 - Two or more functions may have the same name, as...Ch. 6 - Examine the following function header, then write...Ch. 6 - The following statement calls a function named...Ch. 6 - A program contains the following function: int...Ch. 6 - Write a function named timesTen that accepts an...Ch. 6 - A program contains the following function: void...Ch. 6 - Write a function named getNumber that uses a...Ch. 6 - T F Functions should be given names that reflect...Ch. 6 - Prob. 39RQECh. 6 - T F Function prototypes are terminated with a...Ch. 6 - T F If other functions are defined before main,...Ch. 6 - T F When a function terminates, it always branches...Ch. 6 - T F Arguments are passed to the function...Ch. 6 - T F The scope of a parameter is limited to the...Ch. 6 - T F Changes to a function parameter always affect...Ch. 6 - T F In a function prototype, the names of the...Ch. 6 - T F Many functions may have local variables with...Ch. 6 - T F Overuse of global variables can lead to...Ch. 6 - T F Static local variables are not destroyed when...Ch. 6 - T F All static local variables are initialized to...Ch. 6 - T F Initialization of static local variables only...Ch. 6 - T F When a function with default arguments is...Ch. 6 - T F It is not possible for a function to have some...Ch. 6 - T F The exit function can only be called from...Ch. 6 - T F A stub is a dummy function that is called...Ch. 6 - Each of the following functions has errors. Locate...Ch. 6 - double average(int value1, int value2, int value3)...Ch. 6 - void area(int length =30, int width) { return...Ch. 6 - void getValue(int value) { cout "Enter a value:...Ch. 6 - (Overloaded functions) int getValue() { int...Ch. 6 - Markup Write a program that asks the user to enter...Ch. 6 - Rectangle AreaComplete the Program If you have...Ch. 6 - Winning Division Write a program that determines...Ch. 6 - Safest Driving Area Write a program that...Ch. 6 - Falling Distance When an object is falling because...Ch. 6 - Kinetic Energy In physics, an object that is in...Ch. 6 - Celsius Temperature Table The formula for...Ch. 6 - Coin Toss Write a function named coinToss that...Ch. 6 - Present Value Suppose you want to deposit a...Ch. 6 - Future Value Suppose you have a certain amount of...Ch. 6 - Lowest Score Drop Write a program that calculates...Ch. 6 - Star Search A particular talent competition has...Ch. 6 - Days Out Write a program that calculates the...Ch. 6 - Order Status The Middletown Wholesale Copper Wire...Ch. 6 - Overloaded Hospital Write a program that computes...Ch. 6 - Population In a population, the birth rate is the...Ch. 6 - Transient Population Modify Programming Challenge...Ch. 6 - Paint Job Estimator A painting company has...Ch. 6 - Prob. 19PCCh. 6 - Stock Profit The profit from the sale of a stock...Ch. 6 - Multiple Stock Sales Use the function that you...Ch. 6 - isPrime Function A prime number is a number that...Ch. 6 - Prob. 23PCCh. 6 - Rock, Paper, Scissors Game Write a program that...Ch. 6 - Group Project 25. Travel Expenses This program...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
A(n) _____ is a specialized routine that performs a specific operation and then returns a value.
Starting Out With Visual Basic (8th Edition)
Complete and fully test the class Characteristic that Exercise 5 describes. Include the following methods: getD...
Java: An Introduction to Problem Solving and Programming (8th Edition)
Internally, the CPU consists of what two units?
Starting Out with Java: Early Objects (6th Edition)
Which of the following activities do you expect to be performance oriented and which are simulation oriented? a...
Computer Science: An Overview (12th Edition)
Write your own version of malloc and free, and compare its running time and space utilization to the version of...
Computer Systems: A Programmer's Perspective (3rd Edition)
Use the following tables for your answers to questions 3.7 through 3.51 : PET_OWNER (OwnerID, OwnerLasst Name, ...
Database Concepts (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
- I have a running code of a dining philosophers problem but it has a logic problem where it loops right after it asks how many of the philosophers are hungry thus unable to calculate how exactly the philosophers are going to eat below is the code: #include <stdio.h>#include <stdlib.h>#include <conio.h>#include <math.h>#include <string.h> void one(void);void two(void);void exit();int tph, philname[20], howhung, hu[20], cho;//{}[] int main(void){ int i, status[10],philname[10],howhung; printf("\n\nDINING PHILOSOPHER PROBLEM"); printf("\nEnter the total no. of philosophers: "); scanf("%d",&i); for(i=0;i<tph;i++) { philname[i] = (i+1); status[i]=1; } printf("How many are hungry : "); scanf("%d", &howhung); if(howhung==tph) { printf("\nAll are hungry..\nDead lock stage will occur"); printf("\nExiting.."); } else {…arrow_forwardWhat is Output of the following C++ code? #include <iostream> using namespace std; template <typename T> void fun(const T&x) { static int count = 0; cout << "x = " << x << " count = " << count; ++count; return; } int main() { fun<int> (1); cout << endl; fun<int>(1); cout << endl; fun<double>(1.1); cout << endl; return 0; }arrow_forwardUsing C++, create statements that do the following: Define an enum type, birdType, with the values PEACOCK, SPARROW, CANARY, PARROT, PENGUIN, OSTRICH, EAGLE, CARDINAL, and HUMMINGBIRD. Declare a variable bird of the type birdType. Assign CANARY to the variable bird. Advance bird to the next value in the list. Decrement bird to the previous value in the list. Output the value of the variable bird. Input value in the variable bird.arrow_forward
- In C++ Please Modify the program 8-31 from page 584, 585 by adding the following: 1. Add a prototype before main() like: void bubbleSort(Circle [], int); 2. On line 21 add the following function call: bubbleSort(circle, SIZE); 3. After main() function add the definition for bublleSort() function similar to the one on page 628. Evidently you must change the Inventory data type with Circle. The example in the textbook displays all the areas in order because the input is such that will cause the in order output. Your program should display all circles in order even when the input for radii is not in any particular order. // This program uses an array of objects. // The objects are instances of the Circle class. #include <iostream> #include <iomanip> #include "Circle.h" // Circle class declaration file using namespace std; const int NUM_CIRCLES = 4; int main() { Circle circle[NUM_CIRCLES]; // Define an array of Circle objects // Use a loop to initialize the radius of each…arrow_forwardYou are required to make changes in the below programs and introduce the use of compaction where required. FIRST-FIT #include<stdio.h> #include<conio.h> #define max 25 void main() { int frag[max],b[max],f[max],i,j,nb,nf,temp; static int bf[max],ff[max]; clrscr(); printf("\n\tMemory Management Scheme - First Fit"); printf("\nEnter the number of blocks:"); scanf("%d",&nb); printf("Enter the number of files:"); scanf("%d",&nf); printf("\nEnter the size of the blocks:-\n");for(i=1;i<=nb;i++) { printf("Block %d:",i); scanf("%d",&b[i]); } printf("Enter the size of the files :-\n");for(i=1;i<=nf;i++) { printf("File %d:",i); scanf("%d",&f[i]); } for(i=1;i<=nf;i++) { for(j=1;j<=nb;j++) { if(bf[j]!=1) { temp=b[j]-f[i]; if(temp>=0) { ff[i]=j; break; } } } frag[i]=temp; bf[ff[i]]=1; } printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement"); for(i=1;i<=nf;i++) printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]); getch(); }arrow_forwardWhat is pass-by-value? What is pass-by-reference? Show the result of the following programs:arrow_forward
- Question 1 is already done need help with the others though This is the C code I have so far #include <stdio.h> #include <stdlib.h> struct employees { char name[20]; int ssn[9]; int yearBorn, salary; }; struct employees **emps = new employees()[10]; //Added new statement ---- bartleby // function to read the employee data from the user void readEmployee(struct employees *emp) { printf("Enter name: "); gets(emp->name); printf("Enter ssn: "); for(int i =0; i <9; i++) scanf("%d", &emp->ssn[i]); printf("Enter birth year: "); scanf("%d", &emp->yearBorn); printf("Enter salary: "); scanf("%d", &emp->salary); } // function to create a pointer of employee type struct employees *createEmployee() { // creating the pointer struct employees *emp = malloc(sizeof(struct employees)); // function to read the data readEmployee(emp); // returning the data return emp; } // function to…arrow_forwardWhat will be the output of the following C++ function? #include <iostream> using namespace std; template <typename T> T max(T x, T y) { return (x > y)? x : y; } int main() { cout << max(3, 7) << std::endl; cout << max(3.0, 7.0) << std::endl; cout << max(3, 7.0) << std::endl; return 0; }arrow_forwardWhat is the output of the following C++ code? #include<iostream> using namespace std; class X { int m; public: X() : m(10) { } X(int mm): m(mm) { } int getm() { return m; } }; class Y : public X { int n; public: Y(int nn) : n(nn) {} int getn() { return n; } }; int main() { Y yobj( 100 ); cout << yobj.getm() << " " << yobj.getn() << endl; }arrow_forward
- what is the output of the following C++ code? #include <iostream> using namespace std; template<typename T>class clsTemplate { public: T value; clsTemplate(T i) { this->value = i; } void test() { cout << value << endl; } }; class clsChild : public clsTemplate<char> { public: clsChild(): clsTemplate<char>( 0 ) { } clsChild(char c): clsTemplate<char>( c ) { } void test2() { test(); } }; int main() { clsTemplate <int> a( 42 ); clsChild b( 'A' ); a.test(); b.test(); return 0; }arrow_forwardQuestion: Trace and comment each and every line of the C++ program below ; #include <iostream> using namespace std; int binarySearch(int arr[], int left, int right, int num) { if (right >= left) { int mid = left + (right - left) / 2; if (arr[mid] == num) return mid; if (arr[mid] > num) return binarySearch(arr, left, mid - 1, num); return binarySearch(arr, mid + 1, right, num); } return -1; } int main(void) { int arr[] = { 2, 3, 4, 8, 10, 40 }; int check = 40; int n = sizeof(arr) / sizeof(arr[0]); int result = binarySearch(arr, 0, n - 1, check); (result == -1) ? cout << "Element is not present in array" : cout << "Element is present at index " << result; return 0; }arrow_forwardWhat is the output of the following C++ code? #include <iostream> using namespace std; class Base { public: int m; Base(int n=0) : m(n) { cout << "Base" << endl; } }; class Derived: public Base { public: double d; Derived(double de = 0.0) : d(de) { cout << "Derived" << endl; } }; int main() { cout << "Instantiating Base" << endl; Base cBase; cout << "Instantiating Derived" << endl; Derived cDerived; return 0; }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
What Are Data Types?; Author: Jabrils;https://www.youtube.com/watch?v=A37-3lflh8I;License: Standard YouTube License, CC-BY
Data Types; Author: CS50;https://www.youtube.com/watch?v=Fc9htmvVZ9U;License: Standard Youtube License