Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. // testing.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include "pch.h"
  5. #include <iostream>
  6. #include <string>
  7. #include <fstream>
  8. #include <sstream>
  9. #include<queue>
  10. using namespace std;
  11. string A[100];
  12. int top = -1;
  13. int back = -1;
  14. bool isempty = true;
  15. queue<int> myq;
  16. void readFile(const char* filename) {
  17.  
  18. ifstream inf(filename);
  19. string data;
  20. int i = 0;
  21. if (!inf) {
  22. cout << "the file is not open" << endl;
  23. }
  24. else {
  25. if (!inf.eof()) {
  26.  
  27. while (getline(inf, data, ' ')) {
  28. int burst = stoi(data);
  29. myq.push(burst);
  30. top = top + 1;
  31. isempty = false;
  32. back = myq.size();
  33. }
  34. }
  35. cout << myq.front() << endl;
  36. cout << myq.back() << endl;
  37. }
  38. inf.close();
  39. }
  40. void outputFile(const char * filename) {
  41. ofstream out(filename);
  42. int size = myq.size();
  43. if (out) {
  44. for (int i = 1; i <= myq.size(); i++) {
  45. out << "job " << i << ", burst time: " << myq.front() << ", waiting time: " << myq.size()<<endl;
  46. myq.pop();
  47. }
  48. out << "job " << size << ", burst time: " << myq.back() << ", waiting time: " << myq.size() << endl;
  49. }
  50. out.close();
  51. }
  52. int main()
  53. {
  54. readFile("input2.txt");
  55. outputFile("output2.txt");
  56.  
  57.  
  58.  
  59. return 0;
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement