Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 4.3, Problem 5STE
Program Plan Intro
Description of Function:
Function has two parts that are called “function declaration” and “function definition”.
- The function declaration defines how the function is called.
- The function definition defines how the function computes the value it returns.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
2. Consider the following program.
#include <iostream>
using namespace std;
void summer(int&, int);
void fall(int, int&);
int x;
int main() {
int intNum1 = 2;
int intNum2 = 5;
x = 6;
summer(intNum1, intNum2);
cout << intNum1 << " " << intNum2 << " " << x << endl;
fall(intNum1, intNum2);
cout << intNum1 << " " << intNum2 << " " << x << endl;
return 0;
}
void summer(int& a, int b)
{
int intNum1;
intNum1 = b + 12;
a = 2 * b + 5;
b = intNum1 + 4;
}
void fall(int u, int& v)
{
int intNum2;
intNum2 = x;
v = intNum2 * 4;
x = u - v;
}
Answer the following questions:
a. What is the output? Consider variable scope.
b. Considering the function summer, parameter 1 is called by reference. What is passed into the function for parameter 1, i.e., what value does parameter 1 receive?
c. Again, considering the function summer, parameter 2 is called by value. What occurs in memory for parameter 2 and local…
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 {…
What will be the output of the following code snippet? #include <stdio.h>
union example {
long price:
int quantity; float tax;
}:
int main() {
union example val;
val.price = 15; printf("%d", (int)sizeof(val));
val.quantity = 6; val.tax = 0.12;
return 0;
(a) 8 (b) 16
(c) 14
(d) 4
Chapter 4 Solutions
Problem Solving with C++ (10th Edition)
Ch. 4.2 - Prob. 1STECh. 4.2 - Convert each of the following mathematical...Ch. 4.2 - Write a complete C++ program to compute and output...Ch. 4.2 - Write and compile short programs to test the...Ch. 4.3 - Prob. 5STECh. 4.3 - Prob. 6STECh. 4.3 - Prob. 7STECh. 4.3 - Prob. 8STECh. 4.3 - Carefully describe the call-by-value parameter...Ch. 4.3 - Prob. 10STE
Ch. 4.3 - Write a function definition for a function called...Ch. 4.3 - Write a function definition for a function called...Ch. 4.3 - Write a function definition for a function isDigit...Ch. 4.3 - Write a function definition for a function...Ch. 4.4 - What is the purpose of the comment that...Ch. 4.4 - Prob. 16STECh. 4.4 - Prob. 17STECh. 4.4 - Carefully describe the process of program testing.Ch. 4.4 - Prob. 19STECh. 4.5 - If you use a variable in a function definition,...Ch. 4.5 - Suppose a function named Function1 has a variable...Ch. 4.5 - The following function is supposed to take as...Ch. 4.5 - Prob. 23STECh. 4.6 - Prob. 24STECh. 4.6 - Prob. 25STECh. 4.6 - Prob. 26STECh. 4.6 - Suppose you have two function definitions with the...Ch. 4.6 - This question has to do with the Programming...Ch. 4.6 - Prob. 29STECh. 4 - A liter is 0.264179 gallons. Write a program that...Ch. 4 - Modify your program from Practice Program 1 so...Ch. 4 - The price of stocks is sometimes given to the...Ch. 4 - Write a program to gauge the rate of inflation for...Ch. 4 - Enhance your program from the previous Practice...Ch. 4 - Write a function declaration for a function that...Ch. 4 - The gravitational attractive force between two...Ch. 4 - Prob. 8PCh. 4 - Prob. 9PCh. 4 - Write a program that computes the annual after-tax...Ch. 4 - Write a program that asks for the users height,...Ch. 4 - Modify your program from Programming Project 2 so...Ch. 4 - Write a program that outputs the lyrics for the...Ch. 4 - To maintain ones body weight, an adult human needs...Ch. 4 - You have invented a vending machine capable of...Ch. 4 - Your time machine is capable of going forward in...Ch. 4 - Do Programming Project 11 from Chapter 3 except...Ch. 4 - Your sports league uses the following lottery...Ch. 4 - Do Programming Project 14 from Chapter 3, the Edoc...
Knowledge Booster
Similar questions
- 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;arrow_forwardC PROGRAMr Trace the values of the variables and write output of the following: #include<stdio.h>#include<conio.h>void main(){struct myStruct{int a, b;};struct myStruct myArray[5];int i;clrscr( );for(i=0;i<5;i++){myArray[i].a=i;myArray[i].b=5-i;}for(i=0;i<5;i++){printf(“%d %d %d\n”,i, myArray[i].a,myArray[i].b);}getch();}arrow_forwardQuestion 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_forward
- C+++ CODE NEED MISSING CODE BELOW for 5.13.2 Operator Overloading Overload the + operator as indicated. Sample output for the given program with inputs 7 3:First vacation: Days: 7, People: 3 Second vacation: Days: 12, People: 3 #include <iostream>using namespace std; class FamilyVacation { public: void SetNumDays(int dayCount); void SetNumPeople(int peopleCount); void Print() const; FamilyVacation operator+(int moreDays); private: int numDays; int numPeople;}; void FamilyVacation::SetNumDays(int dayCount) { numDays = dayCount;} void FamilyVacation::SetNumPeople(int peopleCount) { numPeople = peopleCount;} // FIXME: Overload + operator so can write newVacation = oldVacation + 5,// which adds 5 to numDays, while just copying numPeople. ******** MISSSING CODE NEEDED GOES HERE. THE REST OF THE CODE CANNOT BE TOUCHED. THANK YOU*************** void FamilyVacation::Print() const { cout << "Days: " << numDays << ",…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_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_forward
- EXPLAIN THIS CODE EACH LINE #include <stdio.h>#include<string.h>int main(){ char name[20]; int meal,quantity; int drink,quantity2; char choose_meal[30] = ""; int meal_price; float drink_price, orderPrice; char choose_drink[30] = ""; float cash, change; printf("--------------------Marry's Fast Food--------------------"); printf("\n"); printf("Enter your name: "); scanf("%s", name); printf("Hello %s!\n", name); printf("\n\nWhat would you like to order?\n"); printf("------------------------MEALS------------------------\n\n"); printf("[1] 1 pc. Chicken Joy....................Php 76.00\n"); printf("[2] 1 pc. w/Jolly spaghetti..............Php 99.00\n"); printf("[3] pc. Spaghetti........................Php 55.00\n"); printf("[4] pc. Burger steak w/rice..............Php 85.00\n"); printf("[5] pc. Burger...........................Php 30.00\n\n"); printf("Choose a number…arrow_forwardIn 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);arrow_forwardIn C++ write a program that generates three random numbers and then find the min number among the generated values, using these three functions: void getrandnum(int &n1, int &n2, int &n3), int findMin(int n1, int n2, int n3), and void printResult(int n1, int n2, int n3, int min). Make the main function drive all these functions.arrow_forward
- What is the output of the following program? #include <iostream>using namespace std;int main(){int first = 16;int second = 8; if ((first / second == 2) || (second / first == 3)){second = 10;first = 20;}else if ((first % second == 2 || second % first == 1)){second = 15;first = 5;}else{first = -10;second = -20;}cout << first << " " << second << endl;return 0;}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#include <iostream> using namespace std; void additionProblem(int topNumber, int bottomNumber) { int userAnswer; cout << "\n\n\n " << topNumber << " + " << bottomNumber << " = "; cin >> userAnswer; cin.ignore(1000, 10); int theAnswer = topNumber + bottomNumber; if (theAnswer == userAnswer) cout << " Correct!" << endl; else cout << " Very good, but a better answer is " << theAnswer << endl; } // additionProblem int main() { additionProblem(8, 2); additionProblem(4, 8); additionProblem(3, 7); additionProblem(4, 10); additionProblem(11, 2); } // main The above code needs to be modified according to the image I've attatched.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