Assignmentx
Assignmentx
Assignmentx
Program:
#include<iostream>
class Complex {
private:
float real;
float imag;
public:
Complex() {
real = 0.0;
imag = 0.0;
}
Complex(float r, float i) {
real = r;
imag = i;
}
int main() {
float real1, imag1, real2, imag2;
return 0;
}
Output:
Enter the real and imaginary parts of the first complex number: 2
Enter the real and imaginary parts of the second complex number: 2
Overloading in C++.
Program code:
#include <iostream>
#include <cmath>
class SeriesSum {
private:
double sum;
public:
SeriesSum() {
sum = 0;
}
SeriesSum(int firstTerm, int commonDifference, int
numberOfTerms) {
sum = 0;
for (int i = 0; i < numberOfTerms; i++) {
sum += firstTerm + i * commonDifference;
}
}
void displaySum() {
std::cout << "Sum: " << sum << std::endl;
}
~SeriesSum() {
}
};
int main() {
SeriesSum arithSeries1(1, 2, 10);
arithSeries1.displaySum();
SeriesSum geoSeries1(2, 2.0, 5, true);
geoSeries1.displaySum();
return 0;
}
Output:
Sum: 100
Sum: 62