Advertisement
Sumss

Tenta c++

Mar 17th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. #ifndef TIME_H
  2. #define TIME_H
  3. /*----------------------------------------------------------------------------*/
  4. #include <ostream>, <sstream>, <string>, <vector>, <array>, <iostream>, <iomanip>, <fstream>, <cassert>, <math.h>
  5. //I cc #include "något.h"
  6. /*----------------------------------------------------------------------------*/
  7. //Bra nyckelord
  8. virtual, public, private, protected, override, const, *, std::, explicit, setfill("-"), setprecistion(2), fixed, setw(4);
  9. //Ex
  10. class Capacitor : public Component
  11. /*----------------------------------------------------------------------------*/
  12. Sorted_List(std::initializer_list<int> li);
  13. std::string to_string() const;
  14. operator std::string() const;
  15. Time operator+(int more_sec);
  16. Time operator-(int rhs);
  17. Time operator++(int);
  18. Time operator--(int);
  19. Time& operator++();
  20. Time& operator--();
  21. bool operator==(Time const &rhs) const;
  22. bool operator<(Time const &rhs) const;
  23. bool operator>(Time const &rhs) const;
  24. bool operator!=(Time const &rhs) const;
  25. bool operator<=(Time const &rhs) const;
  26. bool operator>=(Time const &rhs) const;
  27. Sorted_List& operator=(Sorted_List const & rhs); //Kopiering
  28. Sorted_List& operator=(Sorted_List && rhs); //Flytt
  29. /*----------------------------------------------------------------------------*/
  30. //Iterator klassen ska ligga i klassen för iteratorn
  31. Iterator begin() const;
  32. Iterator end() const;
  33. Iterator operator++(int);
  34. Iterator operator--(int);
  35. Iterator& operator++();
  36. Iterator& operator--();
  37. int operator*();
  38. bool operator!=(Iterator const &rhs) const;
  39. //osv beroende på vilka man behöver
  40. /*----------------------------------------------------------------------------*/
  41. //Ligger utanför men behöver getters
  42. std::ostream& operator<<(std::ostream &lhs, Time const &rhs);
  43. std::istream& operator>>(std::istream &lhs, Time &rhs);
  44. /*----------------------------------------------------------------------------*/
  45. throw (std::domain_error){ "Month " + std::to_string(month) + " doesn't exist!" };
  46. /*----------------------------------------------------------------------------*/
  47. static constexpr const std::array<int, 13> days{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; //days.at(index)
  48. /*----------------------------------------------------------------------------*/
  49. //Skriv ut ett datum då funktionen är friend med ostream
  50. friend std::ostream& operator<<(std::ostream& os, Date rhs);
  51. std::ostream& operator<<(std::ostream& lhs, Date rhs)
  52. {
  53. lhs << std::setfill('0')
  54. << std::setw(4) << rhs.m_year << "-"
  55. << std::setw(2) << rhs.m_month << "-"
  56. << std::setw(2) << rhs.m_day
  57. << std::setfill(' ');
  58. return lhs;
  59. }
  60. /*----------------------------------------------------------------------------*/
  61. //Kompilatorn ska förbjudas att automatiskt konvertera enskilda heltal till en färg?
  62. explicit Color(int rgb);
  63. /*----------------------------------------------------------------------------*/
  64. cin.ignore(1000."\n")
  65. /*----------------------------------------------------------------------------*/
  66. //Ex for infil
  67. std::ifstream ifs{ "STUDENTS.TXT" };
  68. if (!ifs) {
  69. std::cerr << "Couldn't open input file\n";
  70. return 1;
  71. }
  72. else
  73. {
  74. std::string line;
  75. while (std::getline(ifs, line)) //Kan även göras med cin
  76. {
  77. std::stringstream sst{ line };
  78. std::cout << sst.str() << "\n";
  79. }
  80. }
  81. ifs.close();
  82. /*----------------------------------------------------------------------------*/
  83. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement