Concept explainers
define keyword is used to define macros
An object-like macros is defined i.e.
#define pi 3.14
A function-like macros is defined i.e.
#define VOL( x ) ( 4.0 / 3 ) * pi * ( x * x * x )
Variable r is declared to store the value of radius.
printf (): used to print the data onto output screen.
Program Description: Purpose of the program is to define macros tofind the volume of sphere for radius values ranging from 1 to 10 in tabular form.
Explanation of Solution
Program: Following is C++ program that defines macros to find the volume of sphere for radius values ranging from 1 to 10.
#include<stdio.h>//header file for input output //defining macros #define pi 3.14 #define VOL( x ) ( 4.0 / 3 ) * pi * ( x * x * x ) //start of main intmain() { //defining variable for storing value of radius int radius; //tabular reprsentation of data printf( "Radius\tVolume of sphere\n" ); printf( "\n" ); //for loop to iterate over the value of radius ranging from 1 to 10 for (radius = 1; radius < 11; radius++ ) { printf( "%d\t%f\n", radius, VOL( radius ) ); } }//end of main
Explanation:
The given C++ program calculates the volume of sphere.
For declaring the macros statements the define keyword is used for VOL(x) and pi.
Then using the for loop to iterate over the radius variable from 1 to 10 and to print one by one via “\n”. The “\t” is used to print six spaces between the radius and their volume.
Sample Output:
Want to see more full solutions like this?
Chapter 13 Solutions
C How to Program (8th Edition)
- (FreshFood food[], Write a function named void findFreshFoodDetails int noFood) that prompt the user to input the fresh food details that he/she wants to view the price. Display the fresh food, production place and the total price of the selected fresh food according to kilogram as shown in Figure 4.3. Please enter the type of fresh food you wish to purchase: RED ONION Please enter the production place of RED ONION: INDIA Please enter the weight in kg that you want to view the price of the fresh food :3.5 Fresh Food: RED ONION Production Place: INDIA Total price of 3.5kg is RM 14.00 Figure 4.3. foodDetails.txtarrow_forward(I use mindtap on cengage, if that not possible, please use devc++ 5.11) Instructions Assume the definition of Exercise 2, which defines the struct computerType. Write a program that declares a variable of type computerType, prompts the user to input data about a computer, and outputs the computer’s data. Example input and output is shown below: Enter the name of the manufacturer: McPC Enter the model of the computer: 1000 Enter processor type: Intel GFX Enter the size of RAM (in GB): 8 Enter the size of hard drive (in GB): 1000 Enter the year the computer was built: 2016 Enter the price: 1200 Manufacturer: McPC Model: 1000 Processor:…arrow_forward(Rounding Numbers) Function floor can be used to round a number to a specific decimal place. The statementy = floor(x * 10 + 0.5) / 10;rounds x to the tenths position (the first position to the right of the decimal point). The statementy = floor(x * 100 + 0.5) / 100;rounds x to the hundredths position (the second position to the right of the decimal point). Write a program that defines fourfunctions to round a number x in various ways:A. roundToInteger(number)B. roundToTenths(number)C. roundToHundredths(number)D. roundToThousandths(number)For each value read, your program should print the original value, the number rounded to the nearest integer, the number rounded to the nearest tenth, the number rounded to the nearest hundredth and the number rounded to the nearest thousandth.arrow_forward
- (C++ language)arrow_forward(Count the letters in a string) Write a function that counts the number of letters in a string using the following header: def countLetters(s) : Write a test program that prompts the user to enter a string and displays the number of letters in the string. the answer should be in python.arrow_forwardUSE PYTHON Source: en.wikipedia.org/wiki/Camel_case In some languages, it’s common to use camel caseLinks to an external site. (otherwise known as “mixed case”) for variables’ names when those names comprise multiple words, whereby the first letter of the first word is lowercase but the first letter of each subsequent word is uppercase. For instance, whereas a variable for a user’s name might be called name, a variable for a user’s first name might be called firstName, and a variable for a user’s preferred first name (e.g., nickname) might be called preferredFirstName. Python, by contrast, recommendsLinks to an external site. snake caseLinks to an external site., whereby words are instead separated by underscores (_), with all letters in lowercase. For instance, those same variables would be called name, first_name, and preferred_first_name, respectively, in Python. In a file called camel.py, implement a program that prompts the user for the name of a variable in camel case and outputs…arrow_forward
- [Python (py3)] The error in the code below is if the number of rows of the matrix is not equal to its number of columns, matrix addition will not be performed. This should not be the case since the only requirement for matrices addition is that the dimension of Matrix A is equal to the dimension of Matrix B. Please resolve the error in the code below such that Matrix A and Matrix B can be added if the dimension of Matrix A is equal to the dimension of Matrix B. PLEASE do not just copy the code below and use it as the answer itself. I've encountered such case many times. Please modify the code. When the dimension of Matrix A is not equal to the dimension of Matrix B, print "Matrix addition cannot be performed; dimensions are unequal." The input will come from file1.txt, and the output should only be printed to output.txt Format of the input from file1.txt:First Line: type of operation (add)Second Line: matrix A dimension (example: if 3 rows and 2 columns, type 3 2)Third Line: matrix A…arrow_forwardSee attached photo for prompt: a) Write a Python function called func_xy that takes values x and y as arguments and returns the appropriate value of f(x,y). b) Demonstrate that the function works for all relevant cases by inputting different example values.arrow_forward(python) Write a program with a user-defined function called 'clamp', which takes as an input a single integer. If the input number is negative, have the function return zero. If the value is postivie and greater than 255, have the function return 255. If the value is between 0 and 255, have the function return the number unaltered. Write a main program section that prompts the user to enter a number, recasts it to an integer, and calls the clamp function. The program should then print out the value returned by the function call.arrow_forward
- (Attach python file only) 1- Write a user defined function convert_m_to_hm that takes minutes as an input parameter and then returns an object (list or dictionary) that contains the equivalent of minutes in hours and minutes. 2- Call the function convert_m_to_hm(230) and print out the result. A- В I ノ T 三三EE 吕口 esc F1 F2 F3 F4 F5 F6 F7 F8 81arrow_forwardHello! Can you help me in my program: Instructions: In the code, you are provided with a main() function that asks the user for 2 characters, passes these characters to a function call of the getHigherValue() function, and then prints out the ASCII value of the higher character. Your task is to implement the getHigherValue function which has the following details: Return type - int Name - getHigherValue Parameters - 2 characters to be compared Description - the ASCII value of the higher character. Hint: Comparing characters in C is just like comparing integers. DO NOT EDIT ANYTHING IN THE MAIN CODE Input 1. First character 2. Second character Output Enter first character: a Enter second character: h Result value = 104 code: IN BASIC C LANGUAGE OKAY #include<stdio.h> int main() { char a, b; printf("Enter first character: "); a = getchar(); getchar(); printf("Enter second character: "); b = getchar(); getchar();…arrow_forward(python) 9. Create a function based on the following information: You are given two strings with words separated by commas. Try to find what is common between these strings. The words in the same string don't repeat. Your function should find all of the words that appear in both strings. The result must be represented as a string of words separated by commas in alphabetic order. Input: Two arguments as strings. Output: The common words as a string. Return: Nothing is returnedarrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning