-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
84 lines (72 loc) · 1.86 KB
/
main.cpp
File metadata and controls
84 lines (72 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
CS303 Data Structures
Project 1
Due July 1, 2014
Team members: Jordan Larson, Evan Bell, Brenton Klassen
*/
#include "AssignmentHandler.h"
#include <iostream>
#include <stdlib.h>
using namespace std;
void menu(AssignmentHandler);
int getNumber(int, int, std::string = "");
void main()
{
// user's choice
int choice;
// instantiate assignment handler
AssignmentHandler Assignments;
do {
// display menu
cout << "Welcome to the assignment handler!\n\n"
<< "Choose one of the following commands:\n\n"
<< "1. Add a new assignment\n"
<< "2. Complete an assignment\n"
<< "3. Edit an assignment\n"
<< "4. Provide a list of assignments ordered by due date\n"
<< "5. Count the number of late assignments\n"
<< "6. Read assignments from file\n"
<< "7. Exit\n\n";
choice = getNumber(1, 7, "Enter a choice: ");
switch (choice)
{
case 1:
Assignments.addAssignment();
break;
case 4:
Assignments.displayAllAssignments(cout);
break;
default:
cout << "Something's messed up...\n";
break;
}
} while (choice != 7);
Assignments.importAssignmentsFromFile("Assignments.txt");
Assignments.displayAllAssignments(cout);
system("pause");
}
// function to get number from user and take care of incorrect input
int getNumber(int low, int high, std::string message)
{
int number;
bool valid = false;
if (message == "")
message = "Enter a number between " + std::to_string(low) + " and " + std::to_string(high) + ": ";
do
{
std::cout << message;
std::cin >> number;
while (std::cin.fail())
{
std::cout << "You must enter an integer: ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<int>::max(), '\n');
std::cin >> number;
}
if (number < low || number > high)
std::cout << "The number must be between " << low << " and " << high << ".\n";
else
valid = true;
} while (!valid);
return number;
}