WEEK:6 PROGRAMMING ASSIGNMENT 2 SOLUTION (Jan 2020-Apr2020) An Introduction to Programming through C++ NPTEL 2020

  

               An Introduction To Programming Through C++


IIT Bombay.



Week 6- Programming Assignment 2:


Write two overloaded functions sum as follows.  The first function should take two double arguments and return their sum.  The second function should take three double arguments and return their sum.

You should only submit the two functions.  There will be invisible code which will test your functions.  Specifically, we will put in the following main program

int main(){
  double p,q,r,s,t; cin >> p >> q >> r >> s >> t;
  cout << sum(p,q) <<' '<<sum(r,s,t)<<endl;
}

You should not give the main program, just give the definitions of the function sum.  You can also write this using default argument values.
That is also acceptable.


Sample Test Cases
Input Output
Test Case 1
1 2 3 4 5
3 12
Test Case 2
-3 2 9 34 -21
-1 22
Test Case 3
34 21 56 43 45
55 144
Test Case 4
9223372036854775807 2 18446744073709551615 2 2
9.22337e+18 1.84467e+19
Test Case 5
8.5 6.7 -10.5 -10.5 -10.5
15.2 -31.5
Test Case 6
1.17549e-38 -0.00001e-38 3.40282e+38 0.00002e+38 0.00002 e+38

1.17548e-38 3.40284e+38

WRITE/COPY THESE CODE DIRECTLY IN NPTEL TERMINAL AND COMPILE AND RUN THEN SUBMIT.

PROGRAM:



#include <iostream>

using namespace std;
double sum(double p,double q)
{
   double r;
   r=p+q;
   return r;
}
double sum(double r,double s,double t)
{
   double d;
   d=r+s+t;
   return d;
}

WEEK-6 :PROGRAMMING ASSIGNMENT 1 
CLICK ON BELOW LINK.
<<CLICK HERE FOR  WEEK 6:PROGRAMMING -01>>

<<CLICK HERE FOR  WEEK 7: QUIZ>> FOLLOW OUR WEBSITE FROM THE BUTTON PROVIDED TO THE BOTTOM OF PAGE TO GET SOON ANSWERS OF PROGRAMS.
Disclaimer: Here you can find all nptel assignment solutions related to CS stream.These may help you for your assignment.The answers are only for verification.You cannot copy these directly from the post(code of conduct of NPTEL).These is not 100%  correct solutions.

2 comments:

  1. the program is not passing all the test cases

    ReplyDelete
  2. There must be some error recheck or copy the code

    ReplyDelete

If you have any problems related to solutions or any concept please let me know.

Copyright (c) 2020 Custom Programs All Right Reserved

Pages