Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Progres.cpp
- #include "Progres.h"
- Exponential::Exponential(double f, double s) {
- m_first = f;
- m_second = s;
- assert(m_first != 0);
- m_coef = m_second/m_first;
- }
- Exponential::Exponential() {
- m_first = 1;
- m_coef = 1;
- m_second = 1;
- }
- double Exponential::Sum(int n) {
- double ans = m_first * (pow(m_coef, n) - 1) / (m_coef - 1);
- return m_coef != 1 ? ans : n * m_first;
- }
- double Exponential::SerJ(int j) {
- double ans = m_first*(pow(m_coef, j-1));
- return ans;
- }
- std::ostream& operator<< (std::ostream& out, const Exponential& exponential) {
- out << " Первый элемент прогрессии: " << exponential.m_first << "\n Отношение геометрической прогрессии: " << exponential.m_coef << "\n";
- return out;
- }
- Linear::Linear(double f, double s) {
- m_first = f;
- m_second = s;
- m_coef = m_second-m_first;
- }
- Linear::Linear() {
- m_first = 0;
- m_coef = 0;
- m_second = 0;
- }
- double Linear::Sum(int n) {
- return (2 * m_first + m_coef * (n - 1)) * n / 2;
- }
- double Linear::SerJ(int j) {
- double ans = m_first + m_coef*(j-1);
- return ans;
- }
- std::ostream& operator<< (std::ostream& out, const Linear& linear) {
- out << " Первый элемент прогрессии: " << linear.m_first << "\n Отношение ариметической прогрессии: " << linear.m_coef << "\n";
- return out;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement