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

C++ Language ( using just this 4 libraries #include <iostream> #include <string>

ID: 3707463 • Letter: C

Question

C++ Language ( using just this 4 libraries #include <iostream> #include <string> #include<fstream> #include <ctime>)

Often we need to keep track of what we have spent our time on each day. In a business, frequently you might be working on several “billable” tasks at once, so it is important to keep track of how much time you’ve spent on any one thing. This project creates a program that lets a person keep a daily task log in a text file. The data in the log should be formatted in a readable way, and should contain the following information: date, project, start time, end time, time spent (hours:minutes). Time spent should be calculated by the program, not by the user. The user should be able to view the log before entering more information, and should be able to add either one or many items.

Your project must have:

? Analysis – definition of the problem and pseudocode and/or flowchart

? Design – what questions will you ask, what will you do with the information?

? Code – clearly named variables

? Testing – evidence that you tested the program and it worked.

? Documentation – commented code, good style, self-documenting variable names.

This project covers:

? Program flow

? Conditionals

? Loops

? Text Fil

Explanation / Answer

#include<iostream>
#include<cstring>
#include<fstream>
#include<iomanip>
#include<sstream>
#include<cstdlib>

using namespace std;

string calTimeSpent(string st, string stp){
        char *ch;
        ch = strtok((char *)st.c_str(),":");
        int shr = atoi(ch);
        ch = strtok(NULL,":");        
        int smin = atoi(ch);
        int stotmin = shr * 60 + smin;
        ch = strtok((char *)stp.c_str(),":");
        int sthr = atoi(ch);
        ch = strtok(NULL,":");        
        int stmin = atoi((ch));
        int sttotmin = sthr * 60 + stmin;
        int diff = sttotmin - stotmin;
        int hr = diff/60;
        int min = diff % 60;
       
        stringstream ss;
        ss << hr << ":" << min;
        return ss.str();

}

int main(){
    string date,project, st, stp,st1,stp1;
    ofstream fout("log.txt");
    //cout << setw(10) << left << "Date" << setw(15) << "Project" << setw(15) << "Start Time";
    //cout << setw(15) << "Stop Time" << setw(15) << "Time Spent" << endl;
    fout << setw(10) << left << "Date" << setw(15) << "Project" << setw(15) << "Start Time";
    fout << setw(15) << "Stop Time" << setw(15) << "Time Spent" << endl;

    while (true){
        cout << "Enter date dd/mm/yyyy or -1 to quit:";
        getline(cin,date);
        if (date == "-1")
           break;      
        cout << "Enter project:";
        getline(cin,project);        
        cout << "Enter start time (24 hour format)(hours:minutes):";
        getline(cin,st);
        stringstream ss1(st);    
        cout << "Enter stop time (hours:minutes):";
        getline(cin,stp);
        stringstream ss2(stp);
        string time_spent = calTimeSpent(st,stp);
        cout << setw(10) << left << date << setw(15) << project << setw(15) << ss1.str();
        cout << setw(15) << ss2.str() << setw(15) << time_spent << endl;
        fout << setw(10) << left << date << setw(15) << project << setw(15) << ss1.str();
        fout << setw(15) << ss2.str() << setw(15) << time_spent << endl;
    }
    fout.close();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote