Schedule‎ > ‎

15A Practice Final


CS-11M Practice Final Exam Fall 2017

Complete the following programing problems. The point value of each problem is shown inside the parenthesis before the problem statement. You will use the Arduino IDE and your Arduino to compile and run your code.  Your code must compile for you to receive more than half-credit.

You will create 3 files:  practice.ino,  clock.cpp and clock.h

Tip:  Save a copy of all 3 files after you get each major step done so you will always have a working set to turn in. 

Tip:  Since you won’t have access to the internet during the Final,  anything you have to look up while doing the Practice Final should go onto your 8 ½” x 11” reference sheet.

Specifications:

1.      (5) Start a new Arduino project and save the project as "practice" (without the quotes). In the practice.ino file add:

a.       a block comment to the top of the file with your name in the comment.

b.      the <ArduinoSTL.h>

c.       code to the setup() function to set the data rate for serial communication to 9600 baud

2.      (10) Add a Clock class to the project with the correct header and implementation files. In the header file add:

a.       Add the guards – this means the #ifndef, #define and #endif guards

b.      #include "Arduino.h"

c.       using namespace std;

3.       (5) In the Clock class declare three private variables as follows:

int   _hours;

int  _minutes;

int  _seconds;

4.      (3) Put File and Function headers in as you go along

5.      (5) In the Clock class write a function with the following signature to set the values of all three member variables. The function sets the seconds, minutes and hours as elements 0, 1 and 2 respectively.    void setTime(int time[]);

6.      (5) Write a default (no-parameter) constructor for the class that sets valid default values for all the numeric member variables.

7.      (5) Write an overloaded constructor for the class that sets all three member variables to the value of the arguments passed to the parameters by calling the setTime() function.

8.      (5) Write one get() function for each variable of the Clock class following the naming standards for these types of functions. Remember to add the const keyword to all accessor functions.

9.      (10) In the Clock class write a function with the following header that returns the current seconds, minutes and hours as elements 0, 1 and 2 respectively of the vector. Call the function from the practice.ino  file and display the contents of the vector using a for-loop.

vector<int> getTimeVector() const;

10.  (10) In the Clock class write a function named toString() that returns a String that displays the current values of the clock in the format HH:MM:SS, where HH is the value of _hours, MM is the value of _minutes and SS is the value of _seconds. For example: 8:07:09. The leading H is optional when the value of _hours is less than ten.

11.  (10) In the Clock class write a void function named tick() with no parameters that adds one to the value of _seconds and adjusts the _minutes and _hours as need to maintain a valid time. Assume that this is a 24 hour wall clock.

12.  (10) In the practice.ino file write a function with the following signature that asks the user for the hours, minutes and seconds of the clock and constructs a Clock object with those values. The function then returns the Clock object.

Clock setClock()

13.  (5) Declare a global Clock object. Call the setClock() function from the setup() function to set the values of the Clock object.

14.  (5) In the loop() function, call the tick() function of the Clock object. In addition, display the current value of the Clock object by calling toString(). Finally, add a delay(1000) statement to the end of the loop() function.

15.  (10) Write a non-member function in the practice.ino file using recursion that displays a string in reverse and that uses the following prototype:

You do not have to get the String from the  user,   you can hard code it into your program like this:  String myString = “Sharon Strelitz”;   

  1. /**

        Displays the string backwards.

        @param str The string to display in reverse.

    */

    void showBackwards(String str);/*You can use a different prototype if you want*/

                                     Call the function from setup() with your name as the String parameter to display an output to the Serial Monitor like the following: 

                                         Your String backwards:  ztilertS norahS

Remember:  Submit your 3 files to Canvas.  practice.ino, clock.h, clock.cpp

Be sure that your submission compiles.






Comments