-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathganttchart.cpp
More file actions
62 lines (51 loc) · 1.57 KB
/
ganttchart.cpp
File metadata and controls
62 lines (51 loc) · 1.57 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
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
// Define a struct to hold the process details
struct Process
{
string name;
int start_time;
int end_time;
int completion_time;
};
int main()
{
// Define the processes
vector<Process> processes = {
{"Process A", 0, 4, 0},
{"Process B", 1, 3, 0},
{"Process C", 2, 5, 0},
{"Process D", 4, 6, 0},
{"Process E", 5, 7, 0},
};
// Calculate the duration and completion time of each process and determine the maximum completion time
int max_completion_time = 0;
for (auto &process : processes)
{
process.completion_time = process.end_time;
if (process.completion_time > max_completion_time)
{
max_completion_time = process.completion_time;
}
}
// Determine the number of characters needed to represent the maximum completion time
int completion_time_width = to_string(max_completion_time).size();
// Print the chart header
cout << "Gantt Chart: ";
// Print the processes
for (const auto &process : processes)
{
// Calculate the duration and the number of spaces needed for alignment
int duration = process.end_time - process.start_time;
// Print the process name
cout << process.name << " ";
// Print the horizontal bar
cout << string(duration, '-') << " ";
// Print the completion time
cout << setw(completion_time_width) << process.completion_time << " ";
}
return 0;
}