Assignment 4 consists of FIVE (5) exercises: Solved

$24.99 $18.99

To Refresh Your Memory Source Code file – A file containing only code appropriate for the programming language being used. Header file – A source code file designed to be included in another file using #include rather than being compiled directly. The most common extension for header files is .h except for C++ standard library…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

To Refresh Your Memory

  1. Source Code file – A file containing only code appropriate for the programming language being

  1. used.

  1. Header file – A source code file designed to be included in another file using #include rather than

  2. being compiled directly. The most common extension for header files is .h except for C++ standard

  1. library header files, which typically have no extension at all.

  1. Implementation file – A source code file designed to be compiled directly rather than being

  1. included in another file. The most common extension for C implementation files is .c whereas for

  2. C++ it is .cpp.

12

13

14 Writing Programs Using Multiple Source Code Files

15 All exercises in this assignment require that you write multiple functions and place them in separate

16 source code files. This is typical of the way all but the simplest of professional programs are organized

17 and is much more versatile than putting everything into just one file. Any number of files may be added

18 to an IDE project by merely repeating the same steps used to add one file, and the procedure for doing

19 this is explained in detail in the appropriate “Using the Compiler’s IDE…” course document. The IDE will

20 then automatically compile and link these files together and produce a single program. What you must

21 not do is use #include to include an implementation file in any other file, although header files are

22 designed to be included this way.

23

24

25 “Include Guards”

26 Good programming practice dictates that the contents of every header file, but never an

  1. implementation file, be protected by a 3-line “include guard”. This easy to use concept is discussed

  1. and illustrated in note D.2 in appendix D of the course book and a quick example is provided below for

  2. a header file named Hi$tory2File.h. The name of an include guard should be the name of the header

  1. file in all uppercase with any characters that are not allowed in identifiers (note 1.4) replaced by

  2. underbars. In addition, if the file name begins with a numeric character the include guard name must

  1. be preceded by an underbar.

33

34

#ifndef HI_TORY2FILE_H

1st line of include guard

35

#define HI_TORY2FILE_H

2nd line of include guard

36

  1. everything else in the header file…

39 #endif 3rd line of include guard

Personalized C1A4 requirements exclusively for Jose Medrano (U09845800)

C/C++ Programming I (Section 174273)

C1A4E0 (6 points total – 1 point per question – No program required)

Assume language standards compliance and any necessary standard library support unless stated otherwise. These are not trick questions and there is only one correct answer. Basing an answer on actual testing is risky. Place your answers in a plain text “quiz file” named C1A4E0_Quiz.txt formatted as:

a “Non-Code” Title Block, an empty line, then the answers:

  1. A

  2. C etc.

Personalized C1A4 requirements exclusively for Jose Medrano (U09845800)

C/C++ Programming I (Section 174273)

  1. C1A4E1 (3 points – C Program)

  1. Exclude any existing source code files that may already be in your IDE project and add three new ones,

  2. naming them C1A4E1_ComputeMinimum.c, C1A4E1_ComputeMaximum.c, and C1A4E1_main.c. Do

  3. not use #include to include any of these three files in each other or in any other file. However, you

  4. may use it to include any appropriate header file(s) you need.

6

7 File C1A4E1_ComputeMinimum.c must contain a function named ComputeMinimum and

  1. C1A4E1_ComputeMaximum.c must contain a function named ComputeMaximum. Each function must:

  2. 1. Return type double and have exactly two formal parameters, each of type double.

  1. 2. Contain only one statement.

  2. 3. Not use variables other than its formal parameters.

  3. 4. Not use anything that requires #define or #include.

  4. 5. Not use literal values.

  5. 6. Not do assignment, addition, subtraction, multiplication, or division.

  6. 7. Not use if, switch, or looping statements.

  7. 8. Not call functions or macros.

  8. 9. Not display anything.

18

  1. ComputeMinimum must compare its parameter values and return the smallest value passed to it.

  1. ComputeMaximum must do the same for the largest value.

21

  1. File C1A4E1_main.c must contain function main, which must:

  2. 1. Prompt (ask) the user to enter two space-separated decimal values on the same line.

  3. 2. Pass the user-entered values to both ComputeMinimum and ComputeMaximum as arguments.

  4. 3. Display the results of both function calls using the following 2-line format, where the question

  5. marks represent the values passed to and returned from the functions:

27

ComputeMinimum(?, ?) returned ?

28

ComputeMaximum(?, ?) returned ?

29

For example, if the user enters -5.8 5.8 the result should be:

30

ComputeMinimum(-5.8, 5.8) returned -5.8

31

ComputeMaximum(-5.8, 5.8) returned 5.8

32

  1. Do not treat equal values as a special case.

  2. Scientific and standard notation are both okay and may be mixed.

  3. Zeros that do not affect a fractional part’s value may be omitted.

  1. If a fractional part is empty the decimal point may be omitted.

37

  1. Manually re-run your program several times, testing with at least the following 5 sets of user input values,

  2. where each set represents the argument values in left-to-right order:

40

6.9 6.4

6.4 6.9

-5.8 5.8

-0.0 0.0

8.4e3 6.2e-1

41

  1. Submitting your solution

  1. `Send an empty-body email to the assignment checker with the subject line C1A4E1_174273_U09845800

  1. and with all three source code files attached.

  1. See the course document titled “How to Prepare and Submit Assignments” for additional exercise

  2. formatting, submission, and assignment checker requirements.

47

48

  1. Hints:

50 The appropriate solution for ComputeMinimum and ComputeMaximum involves the use of the

  1. conditional” operator described in note 3.16. Simply use it to compare the values of each function’s

  2. parameters and directly return the resulting value.

1992-2022 Ray Mitchell Page 1 of 1 of C1A4E1

Personalized C1A4 requirements exclusively for Jose Medrano (U09845800)

C/C++ Programming I (Section 174273)

  1. C1A4E2 (4 points – C++ Program)

Personalized C1A4 requirements exclusively for Jose Medrano (U09845800)

C/C++ Programming I (Section 174273)

  1. PrintLines(‘C’, 0, 2)outputs two newline characters only

  2. PrintLines(‘C’, 5, 0)outputs nothing, not even a newline character

  1. PrintLines(‘C’, 0, 0)outputs nothing, not even a newline character

57 PrintLines(‘C’, 0) outputs one newline character only

58

59

  1. Submitting your solution

  1. `Send an empty-body email to the assignment checker with the subject line C1A4E2_174273_U09845800

  1. and with your source code file attached.

  1. See the course document titled “How to Prepare and Submit Assignments” for additional exercise

  2. formatting, submission, and assignment checker requirements.

65

66

  1. Hints:

  1. 1. Function overloading is illustrated in note 5.8.

  1. 2. Students are sometimes confused about using a type char variable to obtain the user character

  2. and then passing it as an argument to the PrintLines functions whose first parameter is type int.

  3. However, this is not a problem. When a function is called in the presence of its prototype, all

  4. arguments that are not already the function’s corresponding parameter types are automatically

  5. converted to those types (Note 5.5). Thus, a type char argument passed to PrintLines will be

  6. automatically converted to type int. No cast is necessary to avoid a warning because type int

  7. can represent any value (and more) than type char can represent.

  1. 3. Always declare functions to return type void unless returning a value would serve a meaningful

  1. purpose.

78

79

  1. Example 1: Expected output for an input of % 25 1

  2. %%%%%%%%%%%%%%%%%%%%%%%%%

  1. %%%%%%%%%%%%%%%%%%%%%%%%%

  2. %

  3. Z

85

  1. Example 2: Expected output for an input of J 20 10

  1. JJJJJJJJJJJJJJJJJJJJ

  1. JJJJJJJJJJJJJJJJJJJJ

  2. JJJJJJJJJJJJJJJJJJJJ

  3. JJJJJJJJJJJJJJJJJJJJ

  1. JJJJJJJJJJJJJJJJJJJJ

  2. JJJJJJJJJJJJJJJJJJJJ

  3. JJJJJJJJJJJJJJJJJJJJ

  1. JJJJJJJJJJJJJJJJJJJJ

  2. JJJJJJJJJJJJJJJJJJJJ

  3. JJJJJJJJJJJJJJJJJJJJ

  1. JJJJJJJJJJJJJJJJJJJJ

  2. J

  3. Z

100

  1. Example 3: Expected output for an input of @ 25 0

  1. @@@@@@@@@@@@@@@@@@@@@@@@@

  1. @

  1. Z

1992-2022 Ray Mitchell Page 2 of 2 of C1A4E2

Personalized C1A4 requirements exclusively for Jose Medrano (U09845800)

C/C++ Programming I (Section 174273)

  1. C1A4E3 (3 points – C++ Program)

  1. The purpose of this exercise is to familiarize you with default function arguments. Exclude any existing

  2. source code files that may already be in your IDE project and add two new ones, naming them

  3. C1A4E3_PrintLines.cpp and C1A4E3_main.cpp. Do not use #include to include either of these files in

  4. each other or in any other file. However, you may use it to include any appropriate header file(s) you

  1. need.

7

  1. Required Steps – Exercise 2 Must Be Complete and Cleanly Passing the Assignment Checker

9

Before Proceeding

10

11

1. You should have just

added files C1A4E3_PrintLines.cpp and C1A4E3_main.cpp to your

12

exercise 3 IDE project.

Replace anything they might contain with the entire contents of

13

exercise 2 files C1A4E2_PrintLines-3.cpp and C1A4E2_main.cpp, respectively.

14

2. In file C1A4E3_PrintLines.cpp do only the following – Credit will be deducted for other changes:

15

a. Change the exercise number, file name, and date in the title block. If anything else

16

needs to be changed it’s because the exercise 2 version of this file was written

17

improperly.

18

3. In file C1A4E3_main.cpp do only the following – Credit will be deducted for other changes:

19

a. Change any comment(s) affected by the different requirements of exercise 3.

20

b. Delete the prototypes for the 0, 1, and 2-parameter versions of PrintLines.

21

c. Modify the prototype for the 3-parameter version of PrintLines so the entire program

22

will produce identically the same results as Exercise 2.

23

d. If anything else needs to be changed it is because the exercise 2 version of this file was

24

written improperly.

25

  1. Test your program the same way you tested Exercise 2. The results should be identical in every way.

  1. Submitting your solution

  1. `Send an empty-body email to the assignment checker with the subject line C1A4E3_174273_U09845800

  1. and with your source code file attached.

  1. See the course document titled “How to Prepare and Submit Assignments” for additional exercise

  2. formatting, submission, and assignment checker requirements.

34

35

  1. Hints:

  2. 1. Default function arguments are illustrated in note 5.7. See the bottom of note 5.8 for an

  3. illustration of converting two overloaded functions into a single default argument function.

  4. Standard good practice dictates that you not put default argument values in the declaration

  5. part of a function definition except in very rare cases, which this exercise is not. Default

  6. argument values are used only if actual arguments are not provided.

42

  1. 2. If you’re having trouble determining the default argument values consider required behavior of

  2. the PrintLines functions having less than three parameters in the previous exercise. What

  3. values are they using in place of those omitted parameters?

© 1992-2021 Ray Mitchell Page 1 of 1 of C1A4E3

Personalized C1A4 requirements exclusively for Jose Medrano (U09845800)

C/C++ Programming I (Section 174273)

  1. C1A4E4 (4 points – C++ Program)

  1. Exclude any existing source code files that may already be in your IDE project and add two new ones,

3 naming them C1A4E4_MaxOf.h and C1A4E4_main.cpp. You may not include (#include)

  1. C1A4E4_main.cpp in any other file but you must include C1A4E4_MaxOf.h in any file that needs its

  1. contents.

6

  1. File C1A4E4_MaxOf.h must contain a 2-parameter macro named mMaxOf2, a 3-parameter macro

  2. named mMaxOf3, a 2-parameter “inline” function named fMaxOf2, and 3-parameter “inline” function

  1. named fMaxOf3, as follows:

10

  1. mMaxOf2, mMaxOf3, fMaxOf2, and fMaxOf3 must:

  1. 1. return the maximum value passed to them.

  2. 2. support any arithmetic values within the range and precision of type long double.

  1. 3. not use variables other than their formal parameters.

  2. 4. not need #define or #include, except for the #defines used to define mMaxOf2 and

16 mMaxOf3.

  1. 5. not use literal values.

  2. 6. not use assignment, addition, subtraction, multiplication, or division.

  3. 7. not use if, switch, or looping statements.

  4. 8. not display anything.

21

  1. mMaxOf3 and fMaxOf3 must:

  1. 1. not use the conditional operator (?:) or any relational/equality operators (<, >, ==, etc.)

  1. mMaxOf3 must:

  1. 1. do any needed comparisons using only mMaxOf2, calling it no more than twice.

  2. fMaxOf3 must:

  1. 1. do any needed comparisons using only fMaxOf2, calling it no more than twice.

  2. File C1A4E4_main.cpp must contain function main, which must:

  3. 1. prompt (ask) the user to enter three space-separated decimal values on the same line.

  4. 2. pass the user-entered values to both mMaxOf3 and fMaxOf3 as arguments.

  5. 3. display the results of both calls using the following 2-line format, where the question marks

35

represent the values passed to and returned from the macro and function:

36

mMaxOf3(?, ?, ?) returned ?

37

fMaxOf3(?, ?, ?) returned ?

38

For example, if the user enters -3.8 -3.5 -3.2 the result should be:

39

mMaxOf3(-3.8, -3.5, -3.2) returned -3.2

40

fMaxOf3(-3.8, -3.5, -3.2) returned -3.2

41

  1. Do not define any functions or macros other than main, mMaxOf2, mMaxOf3, fMaxOf2, and fMaxOf3.

  1. Do not attempt to detect cases where the user input values are equal. Instead, simply treat them

  2. exactly like any other values.

  3. Scientific and standard notation are both okay and may be mixed.

  4. Zeros that don’t affect a fractional part’s value may be omitted.

  5. If a fractional part is empty the decimal point may be omitted.

48

  1. Manually re-run your program several times testing with at least the following 4 sets of user input values,

  2. where each set represents the argument values in left-to-right order:

51

-3.8 -3.5 -3.2

-3.2 -3.5 -3.8

-3.5 -3.8 -3.2

8.4e3 6.2e-1 .02e2

52

53

1992-2022 Ray Mitchell

Page 1 of 2 of C1A4E4

Personalized C1A4 requirements exclusively for Jose Medrano (U09845800)

C/C++ Programming I (Section 174273)

  1. Submitting your solution

  1. `Send an empty-body email to the assignment checker with the subject line C1A4E4_174273_U09845800

  1. and with both source code files attached.

  1. See the course document titled “How to Prepare and Submit Assignments” for additional exercise

  2. formatting, submission, and assignment checker requirements.

59

60

  1. Hints:

  2. See note 5.18 for an example of code that is similar to what is expected for a typical mMaxOf2 macro

  3. and note 5.19 for the inline function version (but both of these examples compute the minimum rather

  4. than the maximum). A macro replacement list containing more than one token must be placed in

65 parentheses. In addition, parentheses must be placed around every argument usage in the

  1. replacement list, even if that argument is passed to another macro whose arguments are already

  2. properly parenthesized. However, all of this parenthesizing is neither necessary nor desirable in

  3. equivalent inline functions. Never create prototypes for macros. Be sure to use “include guards” (note

  4. D.2) in header file C1A4E4_MaxOf.h. Use #include to include this file in file C1A4E4_main.cpp.

1992-2022 Ray Mitchell Page 2 of 2 of C1A4E4

Page 9 (7/11/2023)

Assignment 4 consists of FIVE (5) exercises: Solved
$24.99 $18.99