Professional Documents
Culture Documents
Assignment-1-26032022-095650am
Assignment-1-26032022-095650am
Assignment-1-26032022-095650am
SARFRAZ
SOHAIB
AHMED
CLASS: BSCS-2B
ROLL NOS: 01-134212-
035
01-134212-
203
MR.BURHAN ABBASI
OOP THEORY
assignment-1
DIGITAL ALARM CLOCK
Object Oriented Programming
Course Code: CSC 210
Assignment 1
Submission Instructions:
- The assignment is to be submitted in group of 2 members.
- Individual submission is not allowed. For exceptions, please seek prior approval
- Submission deadline is 9 April 2022
- Late submission is not allowed
- Make sure to use this file to submit your solutions.
Submission by:
Name: DANIEL SARFARAZ Enrollment Number: 01-134212-035
Problem Description
Design an Alarm clock application using your knowledge of object-oriented programming. User can set
an alarm for a specific Time (HH:MM:SS AM/PM). User can also set Title of the alarm. Implement your
designed Class in C++ and write down driver program in main function to show the functionality of
your work. All data members must be initialized through Constructor. Destructor should print your
enrollment number.
Solution should be divided into following parts.
Part a: Entity Name
//This function take an hour, min and sec as variables and sets it to the current time. It also sets a bool true or false to determine if
it's AM or PM
void setCurrentTimeVariables(int&, int&, int&, bool&);
class Alarm
{
private:
string title;
int alarmHour, alarmMinute, alarmSecond;
bool isPM;
public:
//Static int tells us how many Alarm objects exist currently
static int alarmCount;
//Constructor takes in title, hour, min, sec and AM/PM variables and sets Object variables to that defining the when the
Alarm should ring. It also increments the Alarm Count
Alarm(string inputTitle, int inputHour, int inputMinute, int inputSecond, char inputAmPm[])
{
title.assign(inputTitle);
alarmHour = inputHour;
alarmMinute = inputMinute;
alarmSecond = inputSecond;
if (!(strcmp(inputAmPm, "PM")))
{
isPM = true;
}
else
{
isPM = false;
}
alarmCount++;
}
//Function compares current time variables to Object variables to determine when the Alarm should ring. Returns true if
the Alarm should ring.
bool alarmCheck()
{
int currentHour, currentMinute, currentSecond;
bool isCurrentlyPM;
//Function rings the Alarm and waits for keypress to stop Alarm.
void ringAlarm()
{
system("CLS");
int i = 0;
cout << "Press any key to stop Alarm: " << title;
while (!_kbhit())
{
Beep(500 + (sin(i) * 200), 100);
i++;
}
}
int Alarm::alarmCount{ 0 };
void newAlarm(vector<Alarm*>&);
void deleteAlarm(vector<Alarm*>&);
void alarmCheck(vector<Alarm*>&);
void shutdown(vector<Alarm*>&);
void main()
{
bool programRunning = true;
while (programRunning)
{
system("CLS");
cout << "\n\n\n" << Alarm::alarmCount << " Current Alarm(s):" << endl;
alarmCheck(alarms);
if (_kbhit())
{
options(programRunning, alarms);
}
Sleep(500);
}
shutdown(alarms);
system("pause");
}
cout << "Press N for New Alarm" << endl << "Press D to Delete an Alarm" << endl << "Press Q to Quit Program" <<
endl << "Press Any Other to go back to Main Menu";
_getch();
char pressedKey = _getch();
system("CLS");
}
void setCurrentTimeVariables(int& currentHour, int& currentMinute, int& currentSecond, bool& isCurrentlyPM)
{
struct tm newtime;
time_t now = time(0);
localtime_s(&newtime, &now);
getline(cin, inputTitle);
string inputNameOfAlarmToDelete;
cout << "Please input the title of the Alarm you want to delete: ";
getline(cin, inputNameOfAlarmToDelete);
currentAlarms.clear();
}
SCREENSHOTS:
THE CURRENT TIME :
MENU BAR:
TITLE SETUP :
TIME SETUP:
ALARM RINGING:
DELETE MENU:
QUIT ALARM: