NPTEL Week-11 Programming in Modern C++ Programming Assignment Oct-2023 Swayam

 

W11_Programming_Qs.1

Due on 2023-10-12, 23:59 IST
Consider the following program (in C++11).
   • Fill in the blanks at LINE-1 and LINE-3 with appropriate template definitions.
   • Fill in the blanks at LINE-2 and LINE-4 to complete the return statements for product
     functions.
The program must satisfy the sample input and output.
Select the Language for this assignment. 
#include <iostream>
 
template <typename T>                   //LINE-1
 
double product(T num){  return num; }    //LINE-2
 
template <typename T, typename... Tail>         //LINE-3
 
double product(T num, Tail... nums){ 
 
    return num * product(nums...);         //LINE-4
}
int main(){
    int a, b, c;
    double d, e, f;
    std::cin >> a >> b >> c;
    std::cin >> d >> e >> f;
    std::cout << product(a, b, c) << " ";
    std::cout << product(d, e, f) << " ";
    std::cout << product(a, b, c, d, e, f);
    return 0;
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
2 3 4
2.3 3.4 4.6
24 35.972 863.328
24 35.972 863.328
Passed
Test Case 2
10 20 30
1.5 2.3 -4.5
6000 -15.525 -93150
6000 -15.525 -93150
Passed


W11_Programming_Qs.2

Due on 2023-10-12, 23:59 IST
Consider the program below (in C++11).
   • Fill in the blank at LINE-1 with appropriate template declaration.
   • Fill in the blanks at LINE-2 with an appropriate universal reference type parameter for
     constructor of class derived and an the appropriate call forwarding to the base class
     constructor.
The program must satisfy the given test cases.
Select the Language for this assignment. 
#include <iostream>
 
class base {
    public:
        base(const int& n) : n_(n * 10){ std::cout << "lvalue : " << n << ", "; }
        base(int&& n) : n_(n * 20) { std::cout << "rvalue : " << n << ", "; }
    protected:
        int n_;
};
class derived : public base {
    public:
         template<typename T>                             //LINE-1
 
        derived(T&& n) : base(std::forward<T>(n)) { }        //LINE-2
 
        void show(){ std::cout << n_ << " "; }
};
int main(){
    int i;
    std::cin >> i;
    derived obj1(i);
    derived obj2(std::move(i));
    obj1.show();
    obj2.show();
    return 0;
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
10
lvalue : 10, rvalue : 10, 100 200
lvalue : 10, rvalue : 10, 100 200 
Passed after ignoring Presentation Error
Test Case 2
50
lvalue : 50, rvalue : 50, 500 1000
lvalue : 50, rvalue : 50, 500 1000 
Passed after ignoring Presentation Error


W11_Programming_Qs.3

Due on 2023-10-12, 23:59 IST
Consider the following program that implements a recursive lambda function to find the sum
of the digits of an input integer.
   • Fill in the blank at LINE-1 to declare the signature of revPrint as std::function.
   • Fill the blank at LINE-2 to complete the definition of lambda function revPrint.
The program must satisfy the sample input and output. 
Your last recorded submission was on 2023-10-07, 22:54 IST
Select the Language for this assignment. 
#include<iostream>
#include<functional>
 
int main() {
  std::function<int(int)> revPrint;    //LINE-1
 
    revPrint = [&revPrint](int n) -> int {     //LINE-2
 
        if (n == 0)
            return 0;
        
        return n % 10 + revPrint(n /= 10);
    };
int a;
    std::cin >> a;
    std::cout << revPrint(a);
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   



Private Test cases used for EvaluationStatus
Test Case 1
Passed






No comments

File Uploading in PHP

  File Uploading in PHP PHP allow you to upload any type of a file i.e. image, binary or text files.etc..,PHP has one in built global variab...