C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Question
error_outline
This textbook solution is under construction.
Students have asked these similar questions
In each of the following code snippets, data is copied from x to y. How many bytes of data arecopied? The answer should be a C expression.Example: int x[10], y[10];...for (int i=0; i<10; i++)x[i] = y[i];Answer: 10*sizeof(int)Example: int *x, *y; ...; y = x;Answer: sizeof(int*)
(e) int x=10, y=x;(f) int x[10]; int *y = x;(g) int x[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};void f(int y[5]) { ... }int main() { f(x); }(h) int x[10], y[10];...memcpy(y, x, 5*sizeof(int));
Modify the program by removing the inner loop. To do this, make sure there should be three input voltages for each piece of equipment.
Code:
using System;class Program{ static void Main() { // Input the voltage data double [,] mat = {{1081,223.7,222.5,223.0}, {2061,220.2,227.0,225.1}, {2405,221.7,224.9,226.0}, {3368,222.9,223.8,226.7}}; int i,j; // Compute the Average of voltage of each equipment and all voltages double total = 0.0; for(i=0;i<4;i++) { double sum = 0.0; for(j=1;j<4;j++) { sum = sum + mat[i,j]; } total = total + sum; Console.WriteLine("Average voltage of equipment number : "+mat[i,0]+" = "+(sum/3)); } Console.Write("Average of all voltages = "+(total/12)); }}
4.16
In Python,
Write a program whose input is two integers. Output the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer.
Ex: If the input is:
-15
30
the output is:
-15 -5 5 15 25
Ex: If the second integer is less than the first as in:
20
5
the output is:
Second integer can't be less than the first.
For coding simplicity, output a space after every integer, including the last.
Knowledge Booster
Similar questions
- Write a program that displays two chessboards, as shown in Figure 6.13. Your program should define at least the following function:# Draw one chessboard whose upper-left corner is at# (startx, starty) and bottom-right corner is at (endx, endy)def drawChessboard(startx, endx, starty, endy):arrow_forwardWrite a program with total change amount as an integer input that outputs the change using the fewest coins, one coin type per line. The coin types are dollars, quarters, dimes, nickels, and pennies. Use singular and plural coin names as appropriate, like 1 penny vs. 2 pennies. Ex: If the input is: 0 or less, the output is: no change Ex: If the input is: 45 the output is: 1 quarter 2 dimes Your program must define and call the following function:void ExactChange(double userTotal, int& numDollars, int& numQuarters, int& numDimes, int& numNickels, int& numPennies)arrow_forward4.16 In Python, Write a program whose input is two integers. Output the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 30 the output is: -15 -5 5 15 25 (with the end starting a new line.) Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than the first. For coding simplicity, output a space after every integer, including the last. creating a new line at the end. (ex: 5 4 3 2 1 )arrow_forward
- Question R .Consider the program segment below : #include <stdio.h> void guess (int,int); int main() { int a = 100, b = 200; int c; printf (“a is %d, b is %d\n”, a, b); guess (a, b); printf (“a is %d, b is %d\n”, a, b); return 0; } void guess (int x, int y) { int value; value = x; x = y; y = value; printf (“x is %d, y is %d\n”, x, y); } A. Identify the function call, the function header and the function prototype. B. What is the data type of x? C. Determine the output. Full explain this question and text typing work only We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this linearrow_forwardWrite a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. n is different than N. Ex: If the input is: n Nobody the output is: 0 Your program must define and call the following function that returns the number of times the input character appears in the input string. int CountCharacters(char userChar, string userString) Note: This is a lab from a previous chapter that now requires the use of a function. #include <iostream>using namespace std; /* Define your function here */ int main() {/* Type your code here. Your code must call the function. */ return 0;} Please help me with this problem using c++.arrow_forwardWrite a program that prompts the user to enter an integer from 1 to 7 and displays a pyramid, as presented in the following sample run ---arrow_forward
- (in Python) Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 10 miles, 50 miles, and 400 miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows:print('{:.2f}'.format(your_value)) Ex: If the input is: 20.0 3.1599 the output is: 1.58 7.90 63.20 Your program must define and call the following driving_cost() function. Given input parameters driven_miles, miles_per_gallon, and dollars_per_gallon, the function returns the dollar cost to drive those miles. Ex: If the function is called with: 50 20.0 3.1599 the function returns: 7.89975 def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon) Your program should call the function three times to determine the gas cost for 10 miles, 50 miles, and 400 miles.arrow_forwardWrite a program that does temperature converter :\n", "- The user will enter if he wants the result in Celsius or in Fahrenheit. Use the input function to read this option. \n", "- Ask the user the value of the temperature he wants to convert. Use the input function to read this value and convert accordingly.\n", "- If the user wants the temperature in Fahrenheit compute: $ Fahrenheit = Celsius*5/9+32$.\n", "- If the user wants the Celsius compute as follows: $ C = (F-32)*5/9 $.\n"arrow_forwardpython Write a program that does temperature converter", "- The user will enter if he wants the result in Celsius or in Fahrenheit. Use the input function to read this option. \n", "- Ask the user the value of the temperature he wants to convert. Use the input function to read this value and convert accordingly.\n", "- If the user wants the temperature in Fahrenheit compute: $ Fahrenheit = Celsius5/9+32$.\n", "- If the user wants the Celsius compute as follows: $ C = (F-32)5/9 $.\n", "\n", "Print the converted temperature and show the unit, like 23.5 C or 67.1 F."arrow_forward
- Consider the following function: int mystery(int x, int y, int z) { if (x <= y && x <= z && x != 0) return (y + z) / x; else if (y <= z && y <= x && y != 0) return (z + x) / y; else if (z <= x && z <= y && z != 0) return (x + y) / z; else return x + y + z; } What is the output of the following C++ statements? i.cout << mystery(1, 0, 0) << endl; ii.cout << mystery(10, 10, 10) << endl;arrow_forwardGiven three int variables that have been given values, areaCode, exchange, and lastFour, write a string expression whose value is the string equivalent of each these variables joined by a single hyphen (-) So if areaCode, exchange, and lastFour, had the values 800, 555, and 1212, the expression's value would be "800-555-1212". Alternatively, if areaCode, exchange, and lastFour, had the values 212, 867 and 5309 the expression's value would be "212-867-5309".arrow_forwardFor the following code, what should be filled in the blank (....) for the string to be outputted 100 times? string str = "Hello\n";int i = 0;do{ cout << str;}while(++i < ....); Group of answer choices 99 100 98 101 None of the above ========================== A variable has ___________ scope when it is declared within { }. Group of answer choices block global variable None of these ===================== For the following code, what is the valid scope for variable "var"? int main(){ for(int var = 0; var < 5; var++){ function1(var); } return 0;} Group of answer choices Only in Main Only in the for-loop Both the for-loop and main Both for-loop and function1 Only in function1 All of the abovearrow_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 Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning