Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "stack"
- #include <iostream>
- #include <cstring>
- #include <fstream>
- using namespace std;
- struct Process
- {
- char Name[20];
- int start_hour;
- int start_minute;
- int end_hour;
- int end_minute;
- int time;
- Process [club6386|*Next];
- };
- class Stack {
- Process *Head;
- stack<Process> s;
- public:
- void add() {
- Process st;
- system("cls");
- cout « "Name: "; cin » st.Name;
- cout « "start hour :"; cin » st.start_hour;
- cout « "start minute"; cin » st.start_minute;
- cout « "end hour"; cin » st.end_hour;
- cout « "end minute"; cin » st.end_minute;
- s.push(st);
- }
- void remove(char name[]) {
- stack<Process> temp = s;
- while (!(temp.empty()))
- {
- if (strcmp(temp.top().Name, name) == 0)
- {
- temp.pop();
- s = temp;
- break;
- }
- temp.pop();
- }
- }
- void sort() {
- stack<Process> temp1;
- stack<Process> temp2;
- stack<Process> temp3;
- temp1 = s;
- temp2 = s;
- temp1.pop();
- while (!(temp1.empty())) {
- if (strcmp(temp1.top().Name, temp2.top().Name) < 0) {
- temp3.push(temp2.top());
- }
- temp1.pop();
- temp2.pop();
- }
- temp3.push(temp2.top());
- if (temp3.empty()) {
- cout « "No need to sort" « endl;
- }
- else {
- s = temp3;
- print_all();
- }
- }
- void search(char name[]) {
- stack<Process> temp = s;
- bool find = false;
- while (!(temp.empty())) {
- if (strcmp(name, temp.top().Name) == 0) {
- cout « temp.top().Name « endl;
- find = true;
- print_one(temp.top());
- }
- temp.pop();
- }
- if (!find) {
- cout « "Not found" « endl;
- }
- }
- int fileLoad(char* filename) {
- ifstream fin(filename);
- if (fin.is_open()) {
- Process *temp;
- while (!fin.eof()) {
- temp = new Process;
- fin
- » temp->Name
- » temp->start_hour
- » temp->start_minute
- » temp->end_hour
- » temp->end_minute;
- s.push(*temp);
- }
- fin.close();
- return 1;
- }
- else {
- cout « "No such file: " « filename « ".\n";
- return 0;
- }
- }
- int fileWrite(char* filename) {
- ofstream fout(filename);
- if (fout) {
- stack<Process> temp;
- temp = s;
- while (!(temp.empty())) {
- fout
- « temp.top().Name « "\t"
- « temp.top().start_hour « "\t"
- « temp.top().start_minute « "\t"
- « temp.top().end_hour « "\t"
- « temp.top().end_minute « "\n";
- temp.pop();
- }
- fout.close();
- return 1;
- }
- else {
- cout « "No such file \"" « filename « "\".\n";
- return 0;
- }
- }
- void print_all() {
- stack<Process> temp;
- temp = s;
- cout « "Name\t\tStart h\t\tStart min\tEnd h\t\tEnd min\n";
- while (!(temp.empty())){
- cout
- « temp.top().Name « "\t\t"
- « temp.top().start_hour « "\t\t"
- « temp.top().start_minute « "\t\t"
- « temp.top().end_hour « "\t\t"
- « temp.top().end_minute « "\n";
- temp.pop();
- }
- }
- void print_one(Process pr) {
- cout « "Name\t\tStart h\t\tStart min\tEnd h\t\tEnd min\n";
- cout
- « pr.Name « "\t\t"
- « pr.start_hour « "\t\t"
- « pr.start_minute « "\t\t"
- « pr.end_hour « "\t\t"
- « pr.end_minute « "\n";
- }
- void time() {
- stack<Process> temp = s;
- cout « "Name\t\tTime" « endl;
- while (!(temp.empty()))
- {
- cout
- « temp.top().Name « "\t\t"
- « (temp.top().end_hour * 60 + temp.top().end_minute) - (temp.top().start_hour * 60 + temp.top().start_minute) « endl;
- temp.pop();
- }
- }
- };
- int main()
- {
- cout.setf(ios::left);
- bool flag = true;
- int choice;
- Process process;
- Stack obj;
- while (flag)
- {
- cout.setf(ios::left);
- system("cls");
- cout « " MENU" « endl;
- cout « " " « endl;
- cout « "1:Read from the file" « endl;
- cout « "2:Show list" « endl;
- cout « "3:Add process" « endl;
- cout « "4:Save to the file" « endl;
- cout « "5:Delete the record" « endl;
- cout « "6:Search" « endl;
- cout « "7:Sort " « endl;
- cout « "8:Time" « endl;
- cout « "9:Exit" « endl;
- cout « " " « endl « endl;
Advertisement
Add Comment
Please, Sign In to add comment