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)
- [Python (py3)] Please create a code that solves for matrix addition and matrix scalar multiplication. The code for scalar multiplication is already written below, just incorporate the code for matrix addition. The input will come from file1.txt, and the output should be printed to output.txt Note for matrix addition: When the dimension of Matrix A is not equal to the dimension of Matrix B, print "Matrix addition cannot be performed; dimensions are unequal." Format of the input from file1.txt:First Line: type of operation (add or scalmultiply)Second Line: matrix A dimension (example: if 3 rows and 2 columns, type 3 2)Third Line: matrix A elementsFourth Line: matrix B dimension (or the scalar number for the operation of scalar multiplication)Fifth Line: matrix B elements (not needed for scalar multiplication) Sample input 1:add2 2 53 -47 312 267 2-34 6 Sample output 1:120 -2-27 37 Sample input 2:scalMultiply2 253 -47 312Sample output 2:106 -814 62…arrow_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_forwardWhat is the output of the following code segment?arrow_forward
- [Python (py3)] Displayed below is an incomplete code for matrix addition, scalar multiplication, and multiplication. Please modify the code below such that: When "add" is read from the input from file1.txt, matrix addition will be performed. When "scalarMultiply" is read from the input from file1.txt, matrix scalar multiplication will be performed. When "multiply" is read from the input from file1.txt, matrix multiplication will be performed. The result for the called matrix operation is printed to output.txt. Sample input 1:add2 353 -4 17 31 22 3 67 2 2-34 6 3 Sample output 1:120 -2 3-27 37 5 Sample input 1.1:add2 2 53 -47 312 367 2 1-34 6 2 Sample Output 1.1:Matrix addition cannot be performed; dimensions are unequal. ________________________________________________________________________________ Sample input 2:scalMultiply2 253 -47 312Sample output 2:106 -814 62 _______________________________________________________________________Sample input 3:multiply3 3 34 10 37 8 346 2 123…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(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_forward
- I CROSS CHECK FROM OTHER SOURCE! DO NOT COPY SOMEONE ELSE AND PLEASE BE SURE TO FOLLOW THE INSTRUCTION TO INCLUDE ALL THAT IS NEEDED!! The code should contain all structure with array, function, and pointer!!!!!! Instruction: Make a C-program with a flowchart using structure with array, function, and pointer that will compute for the average grade of the student. The user will define how many student record will be inputted. Here are the following parameters needed: Name, Student Number, Degree, Course Name 1, Course Name 2, Course Name 3, Course 1 grade, Course 2 grade, Course 3 grade, Average. I have attached the sample output here. The code should contain all structure with array, function, and pointer!!!!!! Unable to combine all necessary inputs will result to unhelpful!arrow_forwardI CROSS CHECK FROM OTHER SOURCE! DO NOT COPY SOMEONE ELSE AND PLEASE BE SURE TO FOLLOW THE INSTRUCTION TO INCLUDE ALL THAT IS NEEDED!! The code should contain all structure with array, function, and pointer!!!!!! Instruction: Make a C-program with a flowchart using structure with array, function, and pointer that will compute for the average grade of the student. The user will define how many student record will be inputted. Here are the following parameters needed: Name, Student Number, Degree, Course Name 1, Course Name 2, Course Name 3, Course 1 grade, Course 2 grade, Course 3 grade, Average. I have attached the sample output here. The code should contain all structure with array, function, and pointer!!!!!! Unable to combine all necessary inputs will result to unhelpful! Please make sure that the program will work if the user will input 2 or more words.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_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(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_forward3. Write a program in C++ to store all the numbers between n and m into an array using a loop. (Note: n <= m). 4. Write a program in C++ to store all odd numbers between n and m into an array using a loop. (Note: n can be greater, equal or less than m and |n-m|<=100). 5. Write a program that accepts two arrays of integers and print true if the first array is equal to the second array, otherwise print false. 6. Write a program in C++ that constructs a two-dimensional array of integers with 6 rows and 8 columns. Fill the array with a multiplication table, so that array element [i][j] contains the value i * j. Then print the array as a table.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning