0% found this document useful (0 votes)
8 views

digital watch project

This document is a C++ program that implements a digital watch application with functionalities such as displaying the current time and date, a stopwatch, and a basic calculator. The program features a menu for user interaction and handles various operations based on user input. It includes functions for each feature and uses a loop to continuously display the menu until the user chooses to exit.

Uploaded by

ahsanali481868
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

digital watch project

This document is a C++ program that implements a digital watch application with functionalities such as displaying the current time and date, a stopwatch, and a basic calculator. The program features a menu for user interaction and handles various operations based on user input. It includes functions for each feature and uses a loop to continuously display the menu until the user chooses to exit.

Uploaded by

ahsanali481868
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream.

h>
#include <conio.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void displayTime();
void displayDate();
void stopwatch();
void calculator();
void displayMenu();

void main() {
int choice;
clrscr();
while (1) {
displayMenu();
cin >> choice;
clrscr();
switch (choice) {
case 1: displayTime(); break;
case 2: displayDate(); break;
case 3: stopwatch(); break;
case 4: calculator(); break;
case 5: exit(0); break;
default: cout << "Invalid choice. Please try again."; break;
}
getch();
clrscr();
}
}

void displayMenu() {
cout << "Digital Watch\n";
cout << "1. Display Time\n";
cout << "2. Display Date\n";
cout << "3. Stopwatch\n";
cout << "4. Calculator\n";
cout << "5. Exit\n";
cout << "Enter your choice: ";
}

void displayTime() {
struct time t;
gettime(&t);
cout << "Current Time: " << (int)t.ti_hour << ":"
<< (int)t.ti_min << ":" << (int)t.ti_sec << "\n";
}

void displayDate() {
struct date d;
getdate(&d);
cout << "Current Date: " << (int)d.da_day << "/"
<< (int)d.da_mon << "/" << (int)d.da_year << "\n";
}

void stopwatch() {
cout << "Press any key to start the stopwatch.\n";
getch();
clrscr();
time_t start, end;
time(&start);
cout << "Stopwatch started. Press any key to stop.\n";
getch();
time(&end);
double elapsed = difftime(end, start);
cout << "Elapsed time: " << elapsed << " seconds\n";
}

void calculator() {
double num1, num2;
char op;
cout << "Enter first number: ";
cin >> num1;
cout << "Enter operator (+, -, *, /): ";
cin >> op;
cout << "Enter second number: ";
cin >> num2;
double result;
switch(op) {
case '+': result = num1 + num2; break;
case '-': result = num1 - num2; break;
case '*': result = num1 * num2; break;
case '/':
if(num2 != 0) result = num1 / num2;
else {
cout << "Cannot divide by zero.";
return;
}
break;
default: cout << "Invalid operator"; return;
}
cout << "Result: " << result << "\n";
}

You might also like