Question

C++ clock.h /* Write a function get_hours that returns an int and accepts an int seconds_since_1970...

C++

clock.h

/*

Write a function get_hours that returns an int and accepts an int seconds_since_1970 parameter

*/

int get_hours(int seconds_since_1970);

/*

Write a function get_minutes that returns an int and accepts an int seconds_since_1970 parameter

*/

int get_minutes(int seconds_since_1970);

/*

Write a function get_seconds that returns an int and accepts an int seconds_since_1970 parameter

*/

int get_seconds(int seconds_since_1970);

clock.cpp

#include "clock.h"

/*

Write get_hours code to return hours given seconds since 1970 int

*/

/*

Write get_minutes code to return minutes given seconds since 1970 int

*/

/*

Write get_seconds code to return seconds given seconds since 1970 int

*/

main.cpp

//Write include statements

#include<iostream>

#include "clock.h"

//write using statements

using std::cout;

/*

Call the functions with argument 1570846218 to display the following time: 02:10:18.

*/

int main()

{

return 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please rate the answer. Let me know for any help with any other questions.

Thank You !
===========================================================================

#ifndef CLOCK_H
#define CLOCK_H


/*
Write a function get_hours that returns an int and accepts an int seconds_since_1970 parameter
*/
int get_hours(int seconds_since_1970);
/*
Write a function get_minutes that returns an int and accepts an int seconds_since_1970 parameter
*/
int get_minutes(int seconds_since_1970);
/*
Write a function get_seconds that returns an int and accepts an int seconds_since_1970 parameter
*/
int get_seconds(int seconds_since_1970);
#endif

=======================================================

#include "clock.h"

#include "clock.h"

/*
Write get_hours code to return hours given seconds since 1970 int
*/
int get_hours(int seconds_since_1970){
   seconds_since_1970 %=24*60*60;
   return seconds_since_1970/3600;
}


/*
Write get_minutes code to return minutes given seconds since 1970 int
*/
int get_minutes(int seconds_since_1970){
   seconds_since_1970 %=24*60*60;
   seconds_since_1970 %=3600;
   return seconds_since_1970/60;
}

/*
Write get_seconds code to return seconds given seconds since 1970 int
*/
int get_seconds(int seconds_since_1970){
   seconds_since_1970 %=24*60*60;
   seconds_since_1970 %=3600;
   seconds_since_1970 %=60;
   return seconds_since_1970;
}

=======================================================

#include<iostream>
#include "clock.h"

//write using statements
using std::cout;
/*

Call the functions with argument 1570846218 to display the following time: 02:10:18.

*/

int main()
{
   int seconds =1570846218 ;
   cout<<get_hours(seconds)<<":"<<get_minutes(seconds)<<":"<<get_seconds(seconds);
return 0;

}

=======================================================

Add a comment
Know the answer?
Add Answer to:
C++ clock.h /* Write a function get_hours that returns an int and accepts an int seconds_since_1970...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ //get_letter_grade.h /* Write a function gpa_to_letter_grade that returns a string and accepts a double gpa...

    C++ //get_letter_grade.h /* Write a function gpa_to_letter_grade that returns a string and accepts a double gpa parameter */ //get_letter_grade.cpp /* Write function code for gpa_to_letter_grade that returns a string and accepts a double gpa parameter YOU MUST USE A SWITCH STATEMENT Given a double 3.5 returns the string A TIP: You'll have to convert the double to an int using multiplication Table 3.5 to 4 returns an A 3.0 to 3.49 returns a B 1.7 to 2.99 returns a C...

  • /* Array expander: Write a function that accepts an int array as argument. The function should...

    /* Array expander: Write a function that accepts an int array as argument. The function should create a new array that is n times the size of the argument array, where n is a user input. The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0. The function should return a pointer to the new array */ #include <iostream> using namespace std; const int NUM_ELEM...

  • (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element...

    (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....

  • Write a generic function int find_lower_bound(T seq[], int n, const T& value). The function returns the...

    Write a generic function int find_lower_bound(T seq[], int n, const T& value). The function returns the index of the largest element in the given sequence that is less than the given value. If multiple elements satisfy, return the one with smallest index. Return -1 if no such element exists. //main.cpp #include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; #include "source.h" struct Point{    int x,y;    bool operator<(const Point& p) {        return (x<p.x || (x==p.x&&y<p.y));    } }; int...

  • For this lab, you will need to write the following functions in table.cpp, and add function...

    For this lab, you will need to write the following functions in table.cpp, and add function prototypes for them to table.h and invoke the functions in main.cpp. * int countNodes(node * root) Recursively count the number of the nodes in the tree. * int sumLeaves(node * root) Recursively sum all of the leaf nodes in the tree. You must use the functions with these exact function prototypes. ****************************************************************************** main.cpp #include "table.h" #include <iostream> using namespace std; int main() { node...

  • a) Make a function which returns x/3 with a given integer x. double third(int x) {...

    a) Make a function which returns x/3 with a given integer x. double third(int x) { //Complete your code below. ______________________________________ return y; } b) Make a program which shows 2 ∗ n with a given user input n. #include<iostream> using namespace std; // Complete the blank. _______________________ int main(){ int n; cout<<"Enter:"; cin>>n; cout<<twice(n); return 0; } int twice(int x){ return 2*x; } c) Make a function which returns true if n is positive, otherwise returns false. ________ positive(int...

  • C++ Write a recursive function that reverses the given input string. No loops allowed, only use...

    C++ Write a recursive function that reverses the given input string. No loops allowed, only use recursive functions. Do not add more or change the parameters to the original function. Do not change the main program. #include <iostream> #include <string> using namespace std; //Write a recursive function 'void reverse(string &str)' that reverses the given input string. void reverse(string &str) { /*Code needed*/ } int main() {    string name = "sherry";    reverse(name);    cout << name << endl; //should...

  • Write a C++ program that contains 2 functions. LastLargestIndex, that takes as paraneters an int array...

    Write a C++ program that contains 2 functions. LastLargestIndex, that takes as paraneters an int array and // its size and returns the index of the first occurrence of the largest element II in the array. Also, write a function to display the array #include ·peh.h" #include <iostream> using namespace std const int ARRAY_SIZE = 15; int main int list[ARRAY SIZE56, 34, 67, 54, 23, 87, 66, 92. 15, 32, 5, 54, 88, 92, 30 cout < List elements: "...

  • C++ Code Pass By Reference Practice Write the following functions for basic array operations based on...

    C++ Code Pass By Reference Practice Write the following functions for basic array operations based on the function descriptions given below. Write the following functions for basic array operations based on the function descriptions given below. FindMinArray: This function will search an array of integers (passed to the function as a parameter) for its minimum value, then return that value. SumArray: This function will sum an array of integers (passed to the function through a parameter) then return that sum....

  • Write this program in c++:

    test.txtLab7.pdfHeres the main.cpp:#include "Widget.h"#include <vector>#include <iostream>#include <string>#include <iomanip>#include <fstream>using std::ifstream;using std::cout;using std::cin;using std::endl;using std::vector;using std::string;using std::setprecision;using std::setw;bool getWidget(ifstream& is, Widget& widget){ string name; int count; float unitCost; if (is.eof())  { return false; } is >> count; is >> unitCost; if (is.fail())  { return false; } is.ignore(); if (!getline(is, name))  { return false; } widget.setName(name); widget.setCount(count); widget.setUnitCost(unitCost); return true;}// place the definitions for other functions here// definition for function mainint main(){ // Declare the variables for main here  // Prompt the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT