Assignment 7 consists of THREE (3) exercises:Solved

$24.99 $18.99

C1A7E0 (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”…

Rate this product

You’ll get a: zip file solution

 

Description

Rate this product

C1A7E0 (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 C1A7E0_Quiz.txt formatted as:

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

  1. A

  2. C etc.

Personalized C1A7 requirements exclusively for Jose Medrano (U09845800)

C/C++ Programming I (Section 174273)

  1. C1A7E1 (7 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 C1A7E1_MyTime.h, C1A7E1_DetermineElapsedTime.cpp, and C1A7E1_main.cpp. Do not

  3. use #include to include either of the two .cpp files in each other or in any other file. However, you may

  4. use it to include any appropriate header file(s) and you must include C1A7E1_MyTime.h in any file that

  5. needs data type MyTime.

7

  1. C1A7E1_MyTime.h must be protected by an include guard (note D.2) and must define type MyTime

  2. exactly as shown below and contain a prototype for function DetermineElapsedTime.

10

struct MyTime {int hours, minutes, seconds;};

11

  1. C1A7E1_DetermineElapsedTime.cpp must contain a function named DetermineElapsedTime that

  2. computes the time elapsed between the start and stop times stored in the two type MyTime structures

  3. pointed to by its two parameters, stores it in another MyTime structure, then returns a pointer to that

  4. structure. For example, if the start time is 03:45:15 (3 hours, 45 minutes, 15 seconds) and the stop time is

  5. 09:44:03, DetermineElapsedTime computes 05:58:48.

  1. IMPORTANT: If the stop time is less than or equal to the start time, the stop time is for the next day.

  1. Function DetermineElapsedTime must:

  2. Have only two parameters, both of type “pointer to const MyTime”.

  3. Not modify the contents of either structure pointed to by its two parameters.

  4. Not declare any pointers other than its two parameters.

  5. Not declare any structures other than one that will hold the elapsed time.

  6. Not prompt or display anything.

  7. Return a “pointer to MyTime” that points to a MyTime structure containing the elapsed time.

25

  1. C1A7E1_main.cpp must contain a function named main that contains a “for” statement whose body

  2. gets executed 3 times. No other looping statements are permitted. The following must be done in order

  1. during each execution:

  1. 1. Prompt the user to enter the start and stop times (in that order), space-separated on the same

  2. line. Each must be in standard HH:MM:SS 2-digit colon-delimited format and the time values

  3. must be input directly into the appropriate members of two MyTime structures.

  1. 2. Although a “real life” program would require that you carefully parse the input to ensure proper

  2. formatting, use the minimalist approach below for this exercise. start is a MyTime structure and

  3. delim is a type char variable whose value you must ignore:

35 cin >> start.hours >> delim >> start.minutes >> delim >> start.seconds

  1. 3. Call DetermineElapsedTime passing pointers to the two structures containing the user-entered

  2. times, then store the pointer it returns in a type “pointer to MyTime” variable.

38 4. Display the user-entered times and the elapsed time in the standard HH:MM:SS 2-digit

  1. colon-delimited format shown below. Use the pointer variable from the previous step to access

  2. the elapsed time:

41 The time elapsed from HH:MM:SS to HH:MM:SS is HH:MM:SS

  1. Function main:

  2. must not contain “if” statements or “?:” expressions.

  3. may declare non-pointer, non-structure, and non-char variables as appropriate, but only one

  4. pointer, two structures, and one char.

46

  1. Use military time for both input and output: 23:59:59 is 1 second before midnight, 00:00:00 is midnight,

  2. and 12:00:00 is noon.

  3. Use no non-constant external variables, including external structure variables.

  4. Use no dynamic storage allocation.

  5. Test with at least the following three start/stop time pairs:

52

00:00:00

00:00:00

12:12:12

13:12:11

13:12:11

12:12:12

1992-2022 Ray Mitchell

Page 1 of 2 of C1A7E1

Personalized C1A7 requirements exclusively for Jose Medrano (U09845800)

C/C++ Programming I (Section 174273)

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

  2. formatting, submission, and assignment checker requirements.

  1. Hints:

57

  1. How to define a structure type and declare and initialize an array of them in 1 statement:

  1. Here is an example in which all members of the first 3 structures in an array of 4 structures named

  2. boxes are initialized explicitly, while all members of the last structure in that array are initialized

  3. implicitly:

62

  1. struct Box

  2. {

65 int height, width, depth, weight;

  1. } boxes[4] = { { 8, 5, 7, 100 }, { 2, 9, 1, 4 }, { 26, 78, 16, 99 } };

  1. Freeing memory

  1. In this exercise you must individually dynamically allocate separate blocks of memory for each of

  2. the foods input by the user. As a result, you must also individually free each of them before the

  3. program terminates.

  4. Testing dynamic memory allocations

  1. Failing to test for successful dynamic memory allocations always is an error.

  1. Uninitialized pointers

  1. Simply declaring a pointer does not make it point to a valid location. All pointers must be explicitly

  2. initialized before dereferencing. In this exercise the three uninitialized name pointers must be made

  3. to point to a usable area of memory before the food names are stored. Dereferencing uninitialized

  4. pointers often causes core dumps (crashes) or even more subtle problems.

  1. Pointers and Memory Diagrams

  1. As with all exercises involving pointers, if you have any doubts or problems, you should draw one or

  2. more diagrams of relevant memory objects showing how they are affected by the various program

  3. steps. In many cases it is beneficial to first draw a diagram of what those objects should look like

  4. when your program has completed its primary task. This will allow you to then step through your

  5. code and verify that it actually produces that configuration. On the next page I have drawn this

  6. finished” memory diagram for you for some typical user food inputs.

91 Please see the diagram on the next page.

1992-2023 Ray Mitchell Page 2 of 3 of C1A7E2

Page 7 (7/11/2023)

Assignment 7 consists of THREE (3) exercises:Solved
$24.99 $18.99