NPTEL Programming in Modern C++ Programming Assignment Week-6 Sept-2023 Swayam

 

W6_Programming_Qs.1

Due on 2023-09-07, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
   • Complete the destructor statement,
   • Complete the constructor statement,
such that it will satisfy the given test cases
Your last recorded submission was on 2023-08-27, 10:38 IST
Select the Language for this assignment. 
#include<iostream>
using namespace std;
class B{
public:
    B(){ cout << "1 "; }
    B(double n){ cout << n << " "; }
 
    virtual ~B(); //LINE-1
};
 
class D : public B{
public:
 
    D(double n) : B(n)     //LINE-2
{ cout << n * 3 << " "; } 
    D(){ cout << "3 "; }
    virtual ~D(){ cout << "4 "; }
};
B::~B(){ cout << "2"; }
int main(){
    int i;
    cin >> i;
    B *pt = new D(i);
    delete pt;
    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
4
4 12 4 2
4 12 4 2
Passed
Test Case 2
2
2 6 4 2
2 6 4 2
Passed


W6_Programming_Qs.2

Due on 2023-09-07, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below.
   • at LINE-1, define fun as pure abstract function,
   • at LINE-2, complete constructor definition,
   • at LINE-3, complete constructor definition,
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-08-27, 10:39 IST
Select the Language for this assignment. 
#include<iostream>
using namespace std;
class Test{
public:
    virtual void fun()=0; //Line-1 
};
class ReTest1 : public Test{
    int d1;
public:
    ReTest1(int n) : d1(n*2){ } //Line-2
    void fun();
};
class ReTest2 : public Test{
    int d2;
public:
    ReTest2(int n) : d2(n*3){ } //Line-3
    void fun(){
        cout << d2;    // copy this line also
    }
};
void ReTest1::fun(){
    cout << d1 << " ";
}
int main(){
    int i;
    cin>>i;
    Test *t1 = new ReTest1(i);
    Test *t2 = new ReTest2(i);
    t1->fun();
    t2->fun();
    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
4 6
4 6
Passed
Test Case 2
3
6 9
6 9
Passed



W6_Programming_Qs.3

Due on 2023-09-07, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below.
   • at LINE-1, declare the function show() as pure virtual function,
   • at LINE-2, with appropriate function call,
   • at LINE-3, with appropriate function header,
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-08-27, 10:40 IST
Select the Language for this assignment. 
#include <iostream>
using namespace std;
class shape{
protected:
    int a,b;
    shape(int x, int y) : a(x), b(y) {}
public:
    virtual void show()=0;    //LINE-1
};
class triangle : public shape{
public:
    triangle(int x, int y) : shape(x,y){}
    void Area();
    void sum();     //Add this line 
    void show(){
        sum(); //LINE-2
        Area();
    }
};
void triangle::sum(){ //LINE-3
    cout << a+b << " ";
}
void triangle::Area(){ cout << (0.5 * a * b); }
int main(){
    int a, b;
    cin >> a >> b;
    shape *sp = new triangle(a, b);
    sp->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 15
25 75
25 75
Passed
Test Case 2
5 10
15 25
15 25
Passed



----------------------------------------------------------------------------------------------------------------------------

No comments

JavaFX Scene Builder

  This is an article about the JavaFX Scene Builder. You will get a short introduction about the installation and usage of the software. The...