Starting Out With C++, Early Objects - With Access Package
8th Edition
ISBN: 9780133441840
Author: GADDIS
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 8.6, Problem 8.13CP
Explanation of Solution
Output of the program:
Program:
//Header file
#include <iostream>
#include <iomanip>
using namespace std;
//Main function
int main()
{
//Declare and initialize the array
double balance[5] = {100.0, 250.0, 325.0 , 500.0,
1100.0};
//Declare the constant value
const double INT_RATE = 0.1;
//Set up the numeric output formatting
cout <<fixed<< showpoint << setprecision(2) ;
//Execute the for loop until the count is less than 5
for (int count = 0; count < 5; count++)
//Calculate the balance
cout << (balance[count] * INT_RATE ) &...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Describe what problem occurs in the following code. What modifications should be made to it to eliminate the problem?
int[] sums = {6, 12, 3, 32, 12, 10, 9, 6};
for (int index = 1; index <= sums.length; index += 1) {
System.out.println(sums[index]);
}
Can someone help me to improve the following code in C and make it functional?
#include <stdio.h>#include <stdlib.h>
void printMaze(int maze[10][10], int posX, int posY){int i;int j;printf("\033[0;0H\033[2J");for (i = 0; i < 10; i++){for (j = 0; j < 10; j++){if (i == posX && j == posY)printf("? ");else{if (maze[i][j] == 0)printf(" _ ");elseprintf("? ");}}printf("\n");}}
void solveMaze(int maze[10][10], int x, int y){printf("posX: %i, posY: %i\n", x, y);if (x == 9 && y == 9){printf("*********Resuelto*********\n");exit(0);}if (maze[x + 1][y] == 0)return solveMaze(maze, x += 1, y);if (maze[x][y + 1] == 0)return solveMaze(maze, x, y += 1);if (maze[x - 1][y] == 0){if (maze[x - 1][y + 1] == 0)return solveMaze(maze, x -= 1, y += 1);}}
int main(void){int option = 0;int count = 0;int maze[10][10] = {{0,0,0,0,0,1,1,1,1,1}, {1,1,1,1,0,1,0,0,0,0}, {1,1,1,1,0,1,0,1,1,0}, {1,0,0,0,0,1,0,1,1,0}, {1,0,1,1,1,1,0,1,0,0}, {0,0,1,1,0,0,0,1,0,1}, {0,1,1,1,0,1,1,1,0,1},…
This is what I have so far
2. Too few parameters
#include <stdio.h>
Void simple();
Int main()
{
Int n;
simple(1,2,3,4,5,6,7,8,9,10,11,12);
Return0;
}
Void simple(int n){
printf(“%d”,n);
printf(%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d)
}
What gets printed?
The values 1 and the garbage values get printed.
Where do the values come from?
The values are some random values generated for the storage part failures like this where we are not allocating values but using them.
Why?
1 is printed as per the statement.
Garbage values are generated because of not having any argument passed to them to locate a specific location.
3. Too small array
Chapter 8 Solutions
Starting Out With C++, Early Objects - With Access Package
Ch. 8.3 - Define the following arrays: A) empNum, a 100...Ch. 8.3 - Prob. 8.2CPCh. 8.3 - Prob. 8.3CPCh. 8.3 - Prob. 8.4CPCh. 8.3 - What is array bounds checking? Does C++ perform...Ch. 8.3 - What is the output of the following code? int...Ch. 8.3 - Complete the following program skeleton so it will...Ch. 8.6 - Define the following arrays: A) ages, a 10-element...Ch. 8.6 - Indicate if each of the following array...Ch. 8.6 - Prob. 8.10CP
Ch. 8.6 - Given the following array definition: int values...Ch. 8.6 - Prob. 8.12CPCh. 8.6 - Prob. 8.13CPCh. 8.6 - What is the output of the following code? const...Ch. 8.8 - Write a typedef statement that makes the name...Ch. 8.8 - Prob. 8.16CPCh. 8.8 - What is the output of the following program...Ch. 8.8 - The following program segments, when completed,...Ch. 8.10 - Prob. 8.19CPCh. 8.10 - Prob. 8.20CPCh. 8.10 - Prob. 8.21CPCh. 8.10 - Prob. 8.22CPCh. 8.10 - Prob. 8.23CPCh. 8.10 - Fill in the empty table below so it shows the...Ch. 8.10 - Write a function called displayArray7. The...Ch. 8.10 - Prob. 8.26CPCh. 8.11 - Prob. 8.27CPCh. 8.11 - Write definition statements for the following...Ch. 8.11 - Define gators to be an empty vector of ints and...Ch. 8.12 - True or false: The default constructor is the only...Ch. 8.12 - True or false: All elements in an array of objects...Ch. 8.12 - What will the following program display on the...Ch. 8.12 - Complete the following program so that it defines...Ch. 8.12 - Add two constructors to the Product structure...Ch. 8.12 - Prob. 8.35CPCh. 8.12 - Prob. 8.36CPCh. 8.12 - Prob. 8.37CPCh. 8.12 - Write the definition for an array of five Product...Ch. 8.12 - Write a structure declaration called Measurement...Ch. 8.12 - Write a structure declaration called Destination ,...Ch. 8.12 - Define an array of 20 Destination structures (see...Ch. 8 - The ________ indicates the number of elements, or...Ch. 8 - The size declarator must be a(n) _______ with a...Ch. 8 - Prob. 3RQECh. 8 - Prob. 4RQECh. 8 - The number inside the brackets of an array...Ch. 8 - C++ has no array ________ checking, which means...Ch. 8 - Prob. 7RQECh. 8 - If a numeric array is partially initialized, the...Ch. 8 - If the size declarator of an array definition is...Ch. 8 - Prob. 10RQECh. 8 - Prob. 11RQECh. 8 - Prob. 12RQECh. 8 - Arrays are never passed to functions by _______...Ch. 8 - To pass an array to a function, pass the ________...Ch. 8 - A(n) ________ array is like several arrays of the...Ch. 8 - Its best to think of a two -dimensional array as...Ch. 8 - Prob. 17RQECh. 8 - Prob. 18RQECh. 8 - When a two -dimensional array is passed to a...Ch. 8 - Prob. 20RQECh. 8 - Look at the following array definition. int values...Ch. 8 - Given the following array definition: int values...Ch. 8 - Prob. 23RQECh. 8 - Assume that array1 and array2 are both 25-element...Ch. 8 - Prob. 25RQECh. 8 - How do you establish a parallel relationship...Ch. 8 - Look at the following array definition. double...Ch. 8 - Prob. 28RQECh. 8 - Prob. 29RQECh. 8 - Prob. 30RQECh. 8 - Prob. 31RQECh. 8 - The following code totals the values in each of...Ch. 8 - In a program you need to store the identification...Ch. 8 - Prob. 34RQECh. 8 - Prob. 35RQECh. 8 - Prob. 36RQECh. 8 - Prob. 37RQECh. 8 - Prob. 38RQECh. 8 - Each of the following functions contains errors....Ch. 8 - Soft Skills Diagrams are an important means of...Ch. 8 - Perfect Scores 1. Write a modular program that...Ch. 8 - Roman Numeral Converter Write a program that...Ch. 8 - Chips and Salsa Write a program that lets a maker...Ch. 8 - Monkey Business A local zoo wants to keep track of...Ch. 8 - Rain or Shine An amateur meteorologist wants to...Ch. 8 - Lottery Write a program that simulates a lottery....Ch. 8 - Rainfall Statistics Write a modular program that...Ch. 8 - Chips and Salsa Version 2 Revise Programming...Ch. 8 - Stats Class and Rainfall Statistics Create a Stats...Ch. 8 - Stats Class and Track Statistics Write a client...Ch. 8 - Prob. 11PCCh. 8 - Drivers License Exam The State Department of Motor...Ch. 8 - Array of Payro11 Objects Design a PayRoll class...Ch. 8 - Drink Machine Simulator Create a class that...Ch. 8 - Bin Manager Class Design and write an object...Ch. 8 - Tic-Tac-Toe Game Write a modular program that...Ch. 8 - Theater Ticket Sales Create a TicketManager class...
Knowledge Booster
Similar questions
- For this assignment please use 2 arrays. Write a program DiscreteDistribution.java that will take an integer command-line argument m, followed by a sequence of positive integer command-line arguments a1,a2,…,ana1,a2,…,an, and will print m random indices (separated by whitespace), choosing each index i with probability proportional to ai.arrow_forwardAny time you design code with an artificial limit someonewill exceed it. For example, consider the code:void err(const char* const fmt, int a = 0, int b = 0, int c = 0, int d = 0, int e = 0){ fprintf(stderr, "Fatal Error:\n"); fprintf(stderr, fmt, a, b, c, d, e); fprintf(stderr, "\n"); abort();}Now this works if you wish to write simple messages:err(“Size parameter (%d) out of range”, size);But what happens when we wish to a slightly more complex call?err(“Point (%d,%d) outside of box (%d,%d), (%d,%d)”, point.x, point.y, box.x1, box.y1, box.x2, box.y2);Our function can take a format and up to five parameters. We just gave itsix. It's not going to work.Now we could fix the err function to add another parameter, but thatwould only work until we needed seven parameter. Another change would beneeded at eight and so on.arrow_forwardWhat is printed by the function foo5()?class Point:def __init__(self, x, y):self.x = xself.y = ydef diff(self, p):self.x = self.x - p.xself.y = self.y - p.ydef show(self):print(self.x, self.y)def foo5():p1 = Point(4, 5)p2 = Point(7, 8)p3 = Point(2, 1)p2.diff(p1)p2.diff(p3)p2.show()p3.show()arrow_forward
- write a python code named get_total_cases() takes the a 2D-list (similar to database) and an integer x from this set {0, 1, 2} as input parameters. Here, 0 represents Case_Reported_Date, 1 represents Age_Group and 2 represents Client_Gender (these are the fields on the header row, the integer value represents the index of each of these fields on that row). This function computes the total number of reported cases for each instance of x in the text file, and it stores this information in a dictionary in this form {an_instance_of_x : total_case}. Finally, it returns the dictionary and the total number of all reported cases saved in this dictionary. (Suppose we want to know the total number of cases reported on each date, so use x = 0.) >>> result, total_cases = get_total_cases(database, 0) >>> display_dict(result) 2021-05-19: 8 2021-05-20: 2 2021-05-21: 1 2021-05-22: 1 >>> print(total_cases)arrow_forwardConsider the following C++ code fragment: int a = 3; int b = 2; double r = a/b; Suppose we want r to have the value 1.5, rather than 1. Which cast operator can be used in the third line to achieve this effect? a. static cast b. dynamic cast c. reinterpret cast d. none of the abovearrow_forwardWhat is wrong with the following code? int *p;. //Line 1int *q;. //Line 2 p = new int [5];. //Line 3 *p = 2; //Line 4 for (int i = 1; i < 5; i++). //Line 5p[i] = p[i-1] + i;. //Line 6 q = p;. //Line 7 delete [] p; //Line 8 for (int j = 0; j < 5; j++) //Line 9 cout << q[j] << " "; //Line 10 cout << endl; //Line 11arrow_forward
- m = int(temp[1]) IndexError: list index out of range line 3, in <module> m = int(temp[10])IndexError: list index out of range when i ran this test case input: 3 jun3 Jin1 Li2 Kitty2 Josh3 Bob1 Dave2 Jose1 David3 Rob3 Anne3 Ann2 Kevin2 Lara1 ALI3 Xin expected output: Li Dave David ALI Kitty Josh Kevin Lara jun Bob Anne Ann Xinarrow_forwardDebug the following program and answer the following questions. #include <stdio.h> typedef struct node { int value; struct node *next; } node; int ll_has_cycle(node *first) { node * head = first; while (head->next) { head = head->next; if (head == first) return 1; } return 0; } void test_ll_has_cycle(void) { int i,j; node nodes[5]; for(i=0; i < sizeof(nodes)/sizeof(node); i++) { nodes[i].next = NULL; nodes[i].value = i; } nodes[0].next = &nodes[1]; nodes[1].next = &nodes[2]; nodes[2].next = &nodes[1]; printf("Checking first list for cycles. There should be a cycle, ll_has_cycle says it has %s cycle\n", ll_has_cycle(&nodes[1])?"a":"no"); printf("Checking length-zero list for cycles. There should be none, ll_has_cycle says it has %s cycle\n",…arrow_forwardExplain this C code line per line please #include <stdio.h> #include <malloc.h> void printArray(int**, int); int main() { int i = 0, j = 0, n = 5; int **arr = (int**)malloc(n * sizeof(int*)); for(int i=0;i<n;i++){ *(arr+i) = (int*)malloc(n*sizeof(int)); } for(i=0;i<n;i++){ for(int j=0;j<n;j++){ *(*(arr+i) + j) = 0; } } printArray(arr, n); for(i=0;i<n;i++){ *( *(arr + i) + i) = i+1; } printArray(arr,n); return 0; } void printArray(int ** array, int size) { int i,j; for(i = 0;i<size;i++){ for(j=0;j<size;j++){ printf("%d ", *( *(array + i) + j)); } printf("\n"); } printf("\n"); }arrow_forward
- briefly comment the code#include <stdio.h>#include <stdlib.h>/* ADJACENCY MATRIX int source,V,E,time,visited[20],G[20][20];void DFS(int i){int j;visited[i]=1;printf(" %d->",i+1);for(j=0;j<V;j++){if(G[i][j]==1&&visited[j]==0)DFS(j);}}int main(){int i,j,v1,v2;printf("\t\t\tGraphs\n");printf("Enter the no of edges:");scanf("%d",&E);printf("Enter the no of vertices:");scanf("%d",&V);for(i=0;i<V;i++){for(j=0;j<V;j++)G[i][j]=0;}/* creating edges :P */for(i=0;i<E;i++){printf("Enter the edges (format: V1 V2) : ");scanf("%d%d",&v1,&v2);G[v1-1][v2-1]=1; } for(i=0;i<V;i++){for(j=0;j<V;j++)printf(" %d ",G[i][j]);printf("\n");}printf("Enter the source: ");scanf("%d",&source);DFS(source-1);return 0;}arrow_forwardWrite code for. Computes the smallest x that satisfies the chinese remainder theorem for a system of equations. The system of equations has the form: x % nums[0] = rems[0] x % nums[1] = rems[1] ... x % nums[k - 1] = rems[k - 1] Where k is the number of elements in nums and rems, k > 0. All numbers in nums needs to be pariwise coprime otherwise an exception is raised returns x: the smallest value for x that satisfies the system of equations.arrow_forwardWrite a function called “CompareTwo” that accepts four parameters: A1 array of type integer, A2 array of type integer, S1 number of elements in A1 array, and S2 number of elements in A2 array. The function must return true if the sum of A1 equals to the sum of A2, otherwise it must return false.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