NPTEL Programming in Modern C++ | Week 4 : Assignment 4 | Jan-2022 | Answers 2022
netaji gandi
Tuesday, February 22, 2022
#include<iostream>
#include<cstring>
using namespace std;
class Complex{
int re, im;
public:
Complex(int r, int i) : re(r), im(i){}
void print(){
cout << re << " + j" << im;
}
friend Complex operator+(const Complex &e, int n); //LINE-1
};
Complex operator+(const Complex &e, int n){ //LINE-2
return Complex(e.re+n,e.im); //LINE-3
}
int main(){
int n;
cin >> n;
Complex c(3, 4);
Complex c1 = c + n;
c1.print();
return 0;
}
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5 | 8 + j4 | 8 + j4 | Passed |
Test Case 2 | 10 | 13 + j4 | 13 + j4 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 2
3 4 | 3 3 | 3 3 | Passed |
Test Case 2 | 3
2 4 6 | 2 2 2 | 2 2 2 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Smart India Hackathon (SIH) 2025: Complete Guide with Problem Statements, Timeline & Idea PPT Template Lets Code • September 8, 2025 I...