NPTEL Programming in Modern C++ Week 6 Programming Assignments Jan-2022

 

Week 6 : Programming Assignment 1

Due on 2022-03-17, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
•at LINE-1 with appropriate function declaration for Area function
•at LINE-2 with appropriate function declaration for Print function
such that it will satisfy the given test cases

If you are using a mobile device then please rotate to landscape orientation for better experience.

Your last recorded submission was on 2022-03-06, 09:21 IST
Select the Language for this assignment. 
1
#include <iostream>
#define PI 3.14
using namespace std;
class Circle{
    protected:
        double radius;
    public:
        Circle(double r) : radius(r) {}
        virtual double Area();    //LINE-1
        virtual void Print();     //LINE-2
};
0
double Circle::Area() { return PI*radius*radius; }
1
void Circle::Print() { cout << Area() << " "; }
2
3
class Cylinder : public Circle{
4
    double height;
5
    public:
6
        Cylinder(double r, double h) : Circle(r), height(h) {}
7
        double Area() { return 2*PI*radius*height; }
8
};
9
10
int main(){
11
    double r, h;
12
    cin >> r >> h;
13
    Circle c1(r);
14
    Cylinder c2(r,h);
15
    Circle *c[2] = {&c1, &c2};
16
    for(int i=0;i<2;i++)
17
        c[i]->Print();
18
        
19
    return 0;
20
}
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
12.56 50.24 
12.56 50.24 
Passed
Test Case 2
5 1
78.5 31.4 
78.5 31.4 
Passed



Private Test cases used for EvaluationStatus
Test Case 1
Passed




Week 6 : Programming Assignment 2

Due on 2022-03-17, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
•at LINE-1 with appropriate keyword,
•at LINE-2 with appropriate statement so that Mul() can access private members of the class,
•at LINE-3 with appropriate statemen
Your last recorded submission was on 2022-03-06, 09:23 IST
Select the Language for this assignment. 
1
#include <iostream>
using namespace std;
class myClass1{
    int data1;
    public:
        myClass1(int d) : data1(d) {}
        virtual void print();                     //LINE-1
        friend void Mul(myClass1 &m1, myClass1 &m2);    //LINE-2
};
class myClass2 : public myClass1{
    int data2;
    public:
        myClass2(int d1, int d2) : myClass1(d1), data2(d2) {}
        void print(){
            myClass1::print();                    //LINE-3
            cout << data2 << " ";
        }
};
0
1
void myClass1::print(){ cout << data1 << " "; }
2
3
void Mul(myClass1 &m1, myClass1 &m2){
4
    m1.data1 = m1.data1 * m2.data1;
5
}
6
7
int main(){
8
    int m, n;
9
    cin >> m >> n;
10
    myClass1 *t1 = new myClass2(m,n);
11
    myClass1 *t2 = new myClass1(m);
12
    Mul(*t1, *t2);
13
    t1->print();
14
    return 0;
15
}
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
4 4 
4 4 
Passed
Test Case 2
3 5
9 5 
9 5 
Passed



Private Test cases used for EvaluationStatus
Test Case 1
Passed




Week 6 : Programming Assignment 3

Due on 2022-03-17, 23:59 IST

Consider the following program. Fill in the blanks as per the instructions given below:
•at LINE-1 with appropriate statement to complete the Base class destructor declaration,
•at LINE-2 with appropriate statement to complete the Derived class destructor declaration
such that it will satisfy the given test cases.
Your last recorded submission was on 2022-03-06, 09:25 IST
Select the Language for this assignment. 
1
#include <iostream>
using namespace std;
class Base{
    int d;
    public:
        Base(int _d);
        virtual ~Base();        //LINE-1
        int get() { return d; }
};
class Derived : public Base{
    public:
        Derived(int _d);
        ~Derived();              //LINE-2
};
0
Base::Base(int _d) : d(_d) { cout << d << " "; }
1
Base::~Base(){ cout << 2*d << " "; }
2
Derived::Derived(int _d) : Base(_d) { cout << 3*_d << " "; }
3
Derived::~Derived() { cout << Base::get() << " "; }
4
5
int main(){
6
    int m;
7
    cin >> m;
8
    Derived *t = new Derived(m);
9
    Base *t1 = t;
10
    delete t1;
11
    return 0;
12
}
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 15 5 10 
5 15 5 10 
Passed
Test Case 2
2
2 6 2 4 
2 6 2 4 
Passed



Private Test cases used for EvaluationStatus
Test Case 1
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...