Advertisement
mariotourist

Untitled

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