Wednesday, September 23, 2020

NPTEL PROGRAMMING IN C++ ASSIGNMENT WEEK 2 ANSWERS 2020(JUL-DEC)

 Question 1:

Complex operator*(Complex &p1, Complex &p2) { // LINE-1
    struct Complex p3 = { 0, 0 };
    p3.x = (p1.x)*(p2.x) - (p1.y)*(p2.y); // LINE-2
    p3.y = (p1.x)*(p2.y) + (p1.y)*(p2.x); // LINE-3
    return p3;
}


Question 2:

#include <iostream>
#include <string>
using namespace std;
void print(string a, string b = "Anyone") { // LINE-1


Question 3:

#include <iostream>
using namespace std;
int Double(int a) { // LINE-1
    return a*2;   // LINE-2
}


Qu
estion 4:

int main() {
    int *p;
    int arr[10];
  p =  arr;// LINE-1
    
    process(p);
    
        
    return 0;
}


1 comment:

  1. I think this is the actual code of Q:4

    int main() {
    int *p;

    p = new int[3]; // LINE-1

    process(p);

    delete p; // LINE-2

    return 0;
    }

    ReplyDelete