NPTEL Programming in Modern C++ Programming Assignment 10 Sept-2023 Swayam

 

W10_Programming_Qs.1

Due on 2023-10-05, 23:59 IST
Consider the following program in C++11/14 to convert between feet and inch. Fill in the
blanks as per the instructions given below:
   • at LINE-1 with appropriate header to function convert,
   • at LINE-2 with appropriate return statement convert,
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-10-04, 17:34 IST
Select the Language for this assignment. 
#include <iostream>
 
class feet; 
 
class inch{
    public: 
        inch(double i) : i_(i){}
        feet getValue();
        void show(){ std::cout << i_ << " "; }
    private:
        double i_;
};
 
class feet{
    public: 
        feet(double f) : f_(f){}
        inch getValue();
        void show(){ std::cout << f_ << " "; }
    private:
        double f_;
};
 
feet inch::getValue(){
    feet t(i_ / 12.0);
    return t;
}
 
inch feet::getValue(){
    inch t(f_ * 12.0);
    return t;
}
template <typename T>
  
decltype(auto) convert(T val)  {     // LINE-1 
    return val.getValue();;                  // LINE-2
}
int main(){
    double a, b;
    std::cin >> a >> b;
    feet f(a);
    inch i(b);
    inch i1 = convert(f); 
    feet f1 = convert(i);
    i1.show();
    f1.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
12 12
144 1
144 1 
Passed after ignoring Presentation Error
Test Case 2
90 90
1080 7.5
1080 7.5 
Passed after ignoring Presentation Error


W10_Programming_Qs.2

Due on 2023-10-05, 23:59 IST
Consider the following program in C++11/14. Fill in the blanks as per the instructions given
below:
   • at LINE-1 with appropriate header and initialization list for the copy constructor,
   • at LINE-2 with appropriate header for copy assignment operator overload,
   • at LINE-3 with appropriate header and initialization list for the move constructor,
   • at LINE-4 with appropriate header for move assignment operator overload,
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-10-04, 17:36 IST
Select the Language for this assignment. 
#include <iostream>
#include <vector>
 
class number { 
    public:
        number(){}
        number(int i) : ip_(new int(i)) { } 
        number(const number& n) : ip_(new int(*(n.ip_) * 10)) { }    // LINE-1: copy constructor 
         number& operator=(const number& n) {      // LINE-2: copy assignment 
            if (this != &n) { 
                delete ip_;  
                ip_ = new int(*(n.ip_) * 10); 
            } 
            return *this;
        }
        ~number() { delete ip_; } 
        number(number&& n) noexcept : ip_(n.ip_ ) { n.ip_ = nullptr; }  // LINE-3: move constructor 
        number& operator=(number&& n)noexcept {        // LINE-4: move assignment 
            if (this != &n) { 
                delete ip_; 
                n.ip_ = nullptr; 
            } 
            return *this;
        }
void show(){
            if(ip_ == nullptr)
                std::cout << "moved : ";
            else
                std::cout << *ip_ << " : ";
        }
        private:
            int* ip_ {nullptr};
};
 
int main(){
    int a;
    std::cin >> a;
    number n1(a);
    number n2 = n1;
    number n3;
    n3 = n1;
    n1.show();
    n2.show();
    n3.show();
    
    number n4 = std::move(n1);
    number n5;
    n5 = std::move(n1);
    n1.show();
    n4.show();
    n5.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
5
5 : 50 : 50 : moved : 5 : moved :
5 : 50 : 50 : moved : 5 : moved : 
Passed after ignoring Presentation Error
Test Case 2
-10
-10 : -100 : -100 : moved : -10 : moved :
-10 : -100 : -100 : moved : -10 : moved : 
Passed after ignoring Presentation Error





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...