C++ How To Program (Early Objects Version), Global Edition, With Access Card, 10 Ed
10th Edition
ISBN: 9780134448848
Author: Paul Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Want to see more full solutions like this?
Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a program in S that computes the function f1(x) = 3x – 3. If you need any macros, please define the
macro expansions. Note that f1(x) is not defined if x = 0.
Write a program that defines and uses a macro to square a random number. Try one of the new random calls in your code. Using C or C++
Let f2(x) be the smallest number n such that x < n2. Write a program in S that computes f2. If you use any macro, you have to provide the corresponding macro expansion.
This question is related to theory of computation and I don't need any answer in C, C++ or any other programming language.
Chapter E Solutions
C++ How To Program (Early Objects Version), Global Edition, With Access Card, 10 Ed
Knowledge Booster
Similar questions
- Write a macro named mGenRandom that generates a random integer between 0 and n 1.Let n be the only parameter.arrow_forwardConsider the code below: void f(int a, int b) { b=5; b=a; } int g() { int i = 3; f(i+1,i); return i; } Explain what function g()returns assuming that macro expansion (textual substitution) is used as a mechanism for passing parameters. Do the same exercise for call-by-value-result.arrow_forwardWrite a macro, mWriteStringAttr, that writes a null-terminated string to the console with a giventext color. The macro, parameters should include the string name and the color. Write a programthat tests your macro with three different strings in three different colors. Here's a sample call: .datamyString BYTE "Here is my string",0•codemWriteStringAttr myString, whitearrow_forward
- COIS 2300HWinter 2023Lab 6 Introduction to Macros in MarsRead about macros here:https://courses.missouristate.edu/kenvollmar/mars/help/MacrosHelp.htmlLab TasksIn the above tutorial on macros, a simple for loop has been implemented using macros. As you can see, it is a powerful tool to simulate code that looks like a statement in a high-level language. The for loop in the tutorial prints a range of consecutive numbers. Copy the code from the tutorial to Mars and make it execute. The macro call: for ($t0, 1, 10, body) will lead to printing numbers from 1 to 10, one each in a new line. Your task is to modify the code to pass another argument (an interval) to the macro so that the numbers are printed with the given interval in the same line where a space separates the numbers. Your program will also print a string (“Here is the output: ”) before the series of numbers using the print_str macro. For example, Macro call: for ($t0, 1, 20, 3, body) will produce the following output: Here is…arrow_forwardFollow up to previous question: Consider the definition of the printint macro:#define printint(n) printf ("%i\n", x ## n) Could the following be used to display the values of the 100 variables x1–x100: for (i = 1; i < 100; ++i) printx (i); Am I right to assume there is no way to get a loop in main() to print the given variables (ie adding x to i) using a #define macro?arrow_forwardIntroduction to Macros in MarsRead about macros here:https://courses.missouristate.edu/kenvollmar/mars/help/MacrosHelp.htmlLab TasksIn the above tutorial on macros, a simple for loop has been implemented using macros. As you can see, it is a powerful tool to simulate code that looks like a statement in a high-level language. The for loop in the tutorial prints a range of consecutive numbers. Copy the code from the tutorial to Mars and make it execute. The macro call: for ($t0, 1, 10, body) will lead to printing numbers from 1 to 10, one each in a new line. Your task is to modify the code to pass another argument (an interval) to the macro so that the numbers are printed with the given interval in the same line where a space separates the numbers. Your program will also print a string (“Here is the output: ”) before the series of numbers using the print_str macro. For example, Macro call: for ($t0, 1, 20, 3, body) will produce the following output: Here is the output: 1 4 7 10 13 16…arrow_forward
- The issue: Unexpected events can occur as a result of parameterized expressions. Suppose the following scenario: #define SQUARE(x) ((x) * (x))int i = 5;int j = SQUARE(i++); What does j stand for? It depends on the programmer, is the response. Additionally, i's worth is unquestionably not 6. Why? Observe the text after the macro has been expanded: int j = ((i++) * (i++)); This demonstrates that i is incremented twice. The exact value of j is also contingent on the compiler because the C++ standard does not specify the order of the operations.arrow_forwardUsing NASM on a linux machine, how can I program to calculate the average of three given numbers stored in memory. Printing them using the C language print function. Put the exit syscall in a macro called EXITPGM. If the Float-sized variable should be initialized to zero and assigned values in move immediate statements.?arrow_forwardWrite a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 3 8 Output: 8 3 Your program must define and call the following function. swap_values() returns the two values in swapped order.def swap_values(user_val1, user_val2) My Code: def swap_values(user_val1, user_val2):temp = user_val1user_val1 = user_val2user_val2 = tempreturn user_val1, user_val2 if __name__ == '__main__': user_val1 = int(input())user_val2 = int(input()) print(swap_values(user_val1, user_val2)) However the output is (8, 3) which is giving me incorrect due to formating, the output needs to be 8 3 without parantheses and comma.arrow_forward
- write a complete program to open a file called numbers.txt that contains only integers. You will first need to define a \textbf{macro}macro called MAX representing a value of 100100 and use it to create a fixed array whose size is MAX. Also, create a variable count whose value will be the total number of integers in the numbers.txt file. Read the numbers from the file into your array. Once you have the whole array, call a function (the name of function should be swapNumbers) that will swap the first and last elements and then print the modified array to the screen (both actions should be done within the function, not within main). For example, if the file contained 4 17 42 23 86, then it should output 86 42 23 17. This function should work for an array of any size.arrow_forwardWrite a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 3 8 the output is: 8 3 Your program must define and call the following function. swap_values() returns the two values in swapped order. def swap_values(user_val1, user_val2) def swap_values(user_val1, user_val2): swap_values(user_val1, user_val2) return user_val1, user_val2 if __name__ == '__main__': user_val1 = input() user_val2 = input() temp = user_val1 user_val1 = user_val2 user_val2 = temp print(user_val1, user_val2)arrow_forwardThere are approximately 3.154e7 seconds in a year. Write a program that takes the age in integer years as input, and prints the equivalent number of seconds as output. a)Prompt the user for their age in whole numbers. b)Calculate the user's age in the number of seconds that they have lived. c)Display the age both in years and in seconds using the scientific notation (with 2 decimal points) like follows:1 year is 3.15e7 seconds. Note: Use a constant macro for the conversion factor. (in C)arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Np Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:Cengage
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage