mariotourist

Untitled

Dec 21st, 2021
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include "Progres.h"
  2.  
  3.  
  4.  
  5. Exponential::Exponential(double f, double s) {
  6.     m_first = f;
  7.     m_second = s;
  8.     assert(m_first != 0);
  9.     m_coef = m_second/m_first;
  10. }
  11.  
  12. Exponential::Exponential() {
  13.     m_first = 1;
  14.     m_coef = 1;
  15.     m_second = 1;
  16. }
  17.  
  18. double Exponential::Sum(int n) {
  19.     double  ans = m_first * (pow(m_coef, n) - 1) / (m_coef - 1);
  20.     return m_coef != 1 ? ans : n * m_first;
  21. }
  22.  
  23. double Exponential::SerJ(int j) {
  24.     double ans = m_first*(pow(m_coef, j-1));
  25.     return ans;
  26. }
  27.  
  28. std::ostream& operator<< (std::ostream& out, const Exponential& exponential) {
  29.  
  30.     out << " Первый элемент прогрессии: " << exponential.m_first << "\n Отношение геометрической прогрессии: " << exponential.m_coef << "\n";
  31.     return out;
  32. }
  33.  
  34. Linear::Linear(double f, double s) {
  35.     m_first = f;
  36.     m_second = s;
  37.     m_coef = m_second-m_first;
  38.  
  39. }
  40.  
  41. Linear::Linear() {
  42.     m_first = 0;
  43.     m_coef = 0;
  44.     m_second = 0;
  45. }  
  46.  
  47. double Linear::Sum(int n) {
  48.     return (2 * m_first + m_coef * (n - 1)) * n / 2;
  49. }
  50.  
  51. double Linear::SerJ(int j) {
  52.     double ans = m_first + m_coef*(j-1);
  53.     return ans;
  54. }
  55.  
  56.  
  57. std::ostream& operator<< (std::ostream& out, const Linear& linear) {
  58.  
  59.  
  60.     out << " Первый элемент прогрессии: " << linear.m_first << "\n Отношение ариметической прогрессии: " << linear.m_coef << "\n";
  61.     return out;
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment