Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Coding Solve the following problems from the book: Engineering analysis and

ID: 3758425 • Letter: C

Question

C++ Coding

Solve the following problems from the book: Engineering analysis and computation Harry H. Cheng, McGraw-Hill, 200 attached a copy of these problems from the book) From Chapter 7 Preprocessing Directives A macro below is supposed to triple its numeric argument. What is wrong with it? Rewrite the macro correctly. #define TRIPLE(a) 3*a Write a program that defines macro MINIMUM2 (x, y) using a conditional operator and use this macro to return the smallest of two numerical values. Input the values from the keyboard. Write a program that defines a macro with one argument to compute the area of a disc. The program should compute the areas for discs of radii from 1 to 10 meters and print the results in the following tabular format. From Chapter 9 Formatted Input and Output

Explanation / Answer

#include<stdio.h>
#define TRIPLE(a) 3*(a)
#define MINIMUM2(a,b) ((a) < (b) ? (a) : (b))
#define AREA(r) 3.14*r*r
int main() {
   int a,b,i;
printf("%d",TRIPLE(3));
printf(" Enter a ,b");
scanf("%d %d",&a,&b);
printf("Minum of %d and %d =%d",a,b,MINIMUM2(a,b));
printf(" radius (m) area(m^2) ");
printf(" ------------------------- ");
for(i=1;i<=10;i++){
   printf("%d %0.2f ",i,AREA(i));
}
return 0;
}

4. #define TRIPLE 3*a

if we call TRIPLE(2+3)

3*2+3 --> 6+3 --> 9

#define TRIPLE 3*(a) is required Since if we call TRIPLE(2+3)

3*(2+3) --> 3*5 --> 15

6. #define MINIMUM2(a,b) ((a) < (b) ? (a) : (b))

10. #define AREA(r) 3.14*r*r