Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
C++ Format
There's an old joke: "Why is 6 scared of 7? Because 7 8 9 (seven ate nine)." But since hearing that joke, I've had an irrational fear of the number 7.
Write a templated function, called "safe_add" that adds two numbers (ints, floats, doubles, etc) and returns there sum. However, if either number (or their sum) contains the number 7, raise a runtime_error stating "can't add because 6+1 appears in it".
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 4 images
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
- ***python only*** Write a function votes_by_race() which takes a list of dicts as a parameter and returns a dict. For example, given the following list: votes = [{'for': 'A, 'age': 35, 'race': 'w'}, {'for': 'B', 'age': 40, 'race': 'b'}, {'for': 'B', 'age': 20, 'race': 'b'}, {'for': 'A', 'age': 30, 'race': 'a'}, {'for': 'A', 'age': 41, 'race': 'w'}, ] The call votes_by_race(votes) should return the following dict:{"White": 2, 'Black': 2, 'Asian': 1, "Hispanic': 0}arrow_forwardWrite in C++ Sam is making a list of his favorite Pokemon. However, he changes his mind a lot. Help Sam write a function insertAfter() that takes five parameters and inserts the name of a Pokemon right after a specific index. Function specifications Name: insertAfter() Parameters (Your function should accept these parameters IN THIS ORDER): input_strings string: The array containing strings num_elements int: The number of elements that are currently stored in the array arr_size int: The number of elements that can be stored in the array index int: The location to insert a new string. Note that the new string should be inserted after this location. string_to_insert string: The new string to be inserted into the array Return Value: bool: true: If the string is successfully inserted into the array false: If the array is full If the index value exceeds the size of the arrayarrow_forwardPLease! in c++ Write a function named “getNonNegativeSum” that takes in 4 input parameters: -a pointer to thearray of integers-its size, -the index tostart the sum from -the count of how many numbers from that starting index It will return the sum of all values from the startingindex with the number count of how many. It will add to the sum if the number in the array is positiveand skip all negative values. If there is an error in the indexor not enough numbers to count, it will return -1. For example,int numList[] = {10, 20, -1, 30}; If the starting index is 1 and the count of 3, it will return 50 If the starting index is 2 and the count of 2, it will return 30 If the starting index is -1 and the count of 2, it will return -1 If the starting index is 2and the count of 5, it will return -1.int priceList[] = {10, 20, 30, -1, 40}; If the starting index is 0, and the count is 1, it will return 10 If the starting index is 1, and the count is 3, itwill return 50 If the starting index is 0,…arrow_forward
- def double(num): num = float(num) return num * 2 double(5.0) I passed 5/6 cases. However, I don't know how to fix the Missing function_call error. Can you please help me?arrow_forward*C Programming This exercise is to help you learn how to debug compiler warnings/errors and other common errors in your code. For each part labeled P(n), there is a warning/error/problem that goes with it. Write down what the issue was in the `Error:` section of each problem. Work on `segfault.c` along with your fixes and error comments. segfault.c file // P0#include <stdio.h>#include <stdlib.h>/* Error: */ void fib(int* A, int n); intmain(int argc, char *argv[]) {int buf[10];unsigned int i;char *str;char *printThisOne;char *word;int *integers;int foo;int *bar;char *someText; // P1for (i = 0; i <= 10; ++i) { buf[i] = i;}for (i = 0; i <= 10; ++i) { printf("Index %s = %s\n", i, buf[i]);}/* Error: */ // P2str = malloc(sizeof(char) * 10);strcpy(str, "Something is wrong");printf("%s\n", printThisOne);/* Error: */ // P3word = "Part 3";*(word + 4) = '-';printf("%s\n", word);/* Error: */ // P4*(integers + 10) = 10;printf("Part 4: %d\n", *(integers +…arrow_forwardIn C++ I need to write templates for the two functions minimum and maximum. The minimum function should accept three arguments and return the value of the argument that is the lesser of the three. The maximum function should accept three arguments and return the value of the argument that is the greater of the three. Design a simple driver program that demonstrates the templates with int, float, and double data types.arrow_forward
- C++ Can someone help me with this problem? I have been trying it but it still doesn't work. Thank youarrow_forwardWrite a c++ function reportDuplicates() that takes a two dimensional integer array as a parameter and identifies the duplicate valuesin the array. The function then reports these to user. Sample input and corresponding output:How many rows? 5How many columns? 2Let’s populate the array:1 86 97 312 522 4Thank you, there are no duplicate elements!How many rows? 3How many columns? 4Let’s populate the array:3 7 5 76 9 7 38 5 12 6Thank you, 3 appears 2 times, 7 appears 3 times, 5 appears 2 times,and 6 appears 2 times.arrow_forwardConsider the function void modify(int & x) { x = 10; }Show how to call the modify function so that it sets the integer int i;to 10.arrow_forward
- For this c++ assignment it must pass the test input as shown belowarrow_forwardc++ include .h file as wellarrow_forwardin the C++ version please suppose to have a score corresponding with probabilities at the end and do not use the count[] function. Please explain the detail when coding. DO NOT USE ARRAY. The game of Pig The game of Pig is a dice game with simple rules: Two players race to reach 100 points. Each turn, a player repeatedly rolls a die until either a 1 ("pig") is rolled or the player holds and scores the sum of the rolls (i.e. the turn total). At any time during a player's turn, the player is faced with two decisions: roll - if the player rolls 1: the player scores nothing and it becomes the opponents turn. 2 - 6: the number is added to the player's turn total and the player's turn continues. hold - The turn total is added to the player's score and it becomes the opponent's turn. This game is a game of probability. Players can use their knowledge of probabilities to make an educated game decision. Assignment specifications Hold-at-20 means that the player will choose to roll…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