Home

Learn Programming & Prepare for NPTEL Exams... Swayam Solver is your one-stop destination for NPTEL exam preparation.

NPTEL Programming in Modern C++ Programming Assignment July-2022 Swayam

NPTEL Programming in Modern C++ Programming Assignment July-2022 Swayam


 Programming In Modern C++


Subscribe to our YouTube Channel :  Swayam Solver


  Please scroll down for latest Programs. 👇 

W1_Programming Qs-1

Due on 2022-08-11, 23:59 IST
Your last recorded submission was on 2022-07-22, 13:52 IST
Select the Language for this assignment. 
1
#include <iostream>
#include<cmath>    //LINE-1 

using namespace std;

struct point{
    int x, y;
};

double get_len(point p1, point p2){

    return sqrt((p1.y-p2.y)*(p1.y-p2.y)+(p1.x-p2.x)*(p1.x-p2.x));    //LINE-2
}
0
int main() { 
1
    int x1, y1, x2, y2;
2
    cin >> x1 >> y1 >> x2 >> y2;
3
    point p1, p2;
4
    p1.x = x1;
5
    p1.y = y1;
6
    p2.x = x2;
7
    p2.y = y2;
8
    cout << get_len(p1, p2);
9
    return 0;
10
}
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 10 20 20
14.1421
14.1421
Passed
Test Case 2
10 20 40 20
30
30
Passed


Private Test cases used for EvaluationStatus
Test Case 1
Passed




W1_Programming Qs-2

Due on 2022-08-11, 23:59 IST
Consider the following program.
• Fill in the blank at LINE-1 with the appropriate header of max_str( ).
• Fill in the blank at LINE-2 with the appropriate statements such that the string array
can be sorted in descending order.
The program must satisfy the sample input and output
Your last recorded submission was on 2022-07-22, 13:53 IST
Select the Language for this assignment. 
#include <iostream>
#include <algorithm>
using namespace std;

bool max_str(string s1, string s2) {    //LINE-1

    return s1>=s2;            //LINE-2
}
0
int main() {
1
    std::string words[5], word;
2
    for(int i = 0; i < 5; i++){
3
        cin >> word;
4
        words[i] = word;
5
    }
6
    sort(words, words + 5, max_str);
7
    for (int i = 0; i < 5; i++)
8
        cout << words[i] << " ";
9
    return 0;
10
}
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
Lion Tiger Bear Hippo Bull
Tiger Lion Hippo Bull Bear 
Tiger Lion Hippo Bull Bear 
Passed
Test Case 2
Wale Fox Deer Frog Crab
Wale Frog Fox Deer Crab 
Wale Frog Fox Deer Crab 
Passed



Private Test cases used for EvaluationStatus
Test Case 1
Passed


W1_Programming Qs-3

Due on 2022-08-11, 23:59 IST
Consider the following program.
• Fill in the blanks at LINE-1 to add each string to the stack.
• Fill in the blanks at LINE-2 to print the element at the top of the stack.
• Fill in the blanks at LINE-3 to remove the element at the top of the stack.
The program must satisfy the sample input and output
Your last recorded submission was on 2022-07-22, 13:54 IST
Select the Language for this assignment. 
#include <iostream>
#include <stack>
#include <vector>

void printReverseOrder(std::vector<std::string> words){
    std::stack<std::string> s;
 
    for(int i = 0; i < words.size(); i++)
        s.push(words[i]);             //LINE-1

    while(!s.empty()){

        std::cout << s.top() << " ";    //LINE-2

        s.pop();             //LINE-3                       
    }
}
0
int main() {
1
    int n;
2
    std::cin >> n;
3
    std::vector<std::string> vec;
4
    for(int i = 0; i < n; i++){
5
        std::string wd;
6
        std::cin >> wd;
7
        vec.push_back(wd);
8
    }
9
    printReverseOrder(vec);
10
    return 0;
11
}
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 Mercury Venus Earth Mars
Mars Earth Venus Mercury 
Mars Earth Venus Mercury 
Passed
Test Case 2
5 Arctic Antarctic Atlantic Pacific Indian
Indian Pacific Atlantic Antarctic Arctic 
Indian Pacific Atlantic Antarctic Arctic 
Passed
Private Test cases used for EvaluationStatus
Test Case 1
Passed


Don't forget to subscribe to the channel.











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







W2_Programming QS-1

Due on 2022-08-11, 23:59 IST
Consider the program below which defines a type point and overloads operator + such that the x and y coordinates of a given point can be added with an integer.
Complete the program with the following instructions.
 Fill in the blank at LINE-1 with the appropriate header of the function to overload operator +.
 Fill in the blank at LINE-2 to declare a new point.
 Fill in the blank at LINE-3 to return the new point.
Your last recorded submission was on 2022-08-06, 19:03 IST
Select the Language for this assignment. 
1
#include <iostream>
2
using namespace std;
3
4
struct point {
5
    int x, y;
6
};
point operator+(point pt, int t){    //LINE-1
    point new_pt;       //LINE-2
    new_pt.x = pt.x + t;
    new_pt.y = pt.y + t;
    return new_pt;       //LINE-3
}
0
int main() {
1
    int a, b, c;
2
    cin >> a >> b >> c;
3
    point p = {a, b};
4
    int t = c;
5
    point np = p + t;
6
    cout << "(" << np.x << ", " << np.y << ")";
7
    return 0;
8
}
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 20 -5
(5, 15)
(5, 15)
Passed
Test Case 2
100 100 10
(110, 110)
(110, 110)
Passed

Private Test cases used for EvaluationStatus
Test Case 1
Passed







W2_Programming QS-2

Due on 2022-08-11, 23:59 IST
Consider the following program. Fill in the blanks at LINE-1 and LINE-2 with appropriate headers of overloaded function product. The program must satisfy the sample input and output.
Your last recorded submission was on 2022-08-06, 19:04 IST
Select the Language for this assignment. 
1
#include <iostream>
using namespace std;
int product (int a, int b=1, int c=1) {
    return a * b * c;
}
double product (double a, double b) {
    return a * b;    
}
0
int main() {
1
    int i1, i2, i3;
2
    double d1, d2;
3
    cin >> i1 >> i2 >> i3 >> d1 >> d2;
4
    cout << product(i1) << ", ";
5
    cout << product(i1, i2) << ", ";
6
    cout << product(i1, i2, i3) << ", ";
7
    cout << product(d1, d2);
8
    return 0;
9
}
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 20 30 10.5 5.67
10, 200, 6000, 59.535
10, 200, 6000, 59.535
Passed
Test Case 2
-10 20 50 3.14 10
-10, -200, -10000, 31.4
-10, -200, -10000, 31.4
Passed


Private Test cases used for EvaluationStatus
Test Case 1
Passed






W2_Programming Qs-3

Due on 2022-08-11, 23:59 IST
Consider the following program. Fill in the blank at LINE-1 with an appropriate function header for the function update_and_sum( ) such that it satisfies the sample input and output.
Your last recorded submission was on 2022-08-06, 19:05 IST
Select the Language for this assignment. 
1
#include <iostream>
using namespace std;
void update_and_sum( int a, int b, int & c) {    //LINE-1
0
    a *= 10;
1
    b *= 10;
2
    c = a + b;
3
    cout << a << ", " << b << ", " << c << endl;
4
}
5
int main() {
6
    int i1, i2, i3 = 0;
7
    cin >> i1 >> i2;
8
    update_and_sum(i1, i2, i3);
9
    cout << i1 << ", " << i2 << ", " << i3 << endl;
10
    return 0;
11
}
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 20
100, 200, 300\n
10, 20, 300\n
100, 200, 300\n
10, 20, 300\n
Passed
Test Case 2
-10 300
-100, 3000, 2900\n
-10, 300, 2900\n
-100, 3000, 2900\n
-10, 300, 2900\n
Passed



Private Test cases used for EvaluationStatus
Test Case 1
Passed




Subscribe to our YouTube Channel :  Swayam Solver







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





W3_Programming QS-1

Due on 2022-08-18, 23:59 IST
Consider the program below which defines a class Complex.
Complete the program with the following instructions.
• Fill in the blank at LINE-1 to complete parameterized constructor.
• Fill in the blank at LINE-2 to complete copy constructor.
• Fill in the blank at LINE-3 and LINE-4 to complete the sum function.
Your last recorded submission was on 2022-08-14, 14:06 IST
Select the Language for this assignment. 
1
#include<iostream>
#include<cmath>
using namespace std;
class Complex{
    const int x,y;
public:
    Complex(int _x=0, int _y=0) : x(_x), y(_y) {} //LINE-1

    Complex(const Complex& c) : x(c.x),y(c.y) {} //LINE-2

    void sum(Complex p){
        int rx = this->x + p.x; //LINE-3

        int ry = this->y + p.y; //LINE-4
0
        cout << "(" << rx << "," << ry << ")" << endl;
1
    }
2
    void print(){ cout << "(" << x << "," << y << ")" << endl; }
3
};
4
5
6
int main(){
7
    int x1,x2,y1,y2;
8
    cin >> x1 >> y1 >> x2 >> y2;
9
    Complex c1(x1,y1), c2(x2,y2);
10
    c1.print();
11
    c2.print();
12
    c1.sum(c2);
13
    return 0;
14
}
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
1 2 3 4
(1,2)\n
(3,4)\n
(4,6)\n
(1,2)\n
(3,4)\n
(4,6)\n
Passed
Test Case 2
5 10 15 20
(5,10)\n
(15,20)\n
(20,30)\n
(5,10)\n
(15,20)\n
(20,30)\n
Passed






Private Test cases used for EvaluationStatus
Test Case 1
Passed










W3_Programming QS-2

Due on 2022-08-18, 23:59 IST
Consider the following program.
• Fill in the blanks at LINE-1 and LINE-2 with an appropriate constructor and destructor
  statement.
• Fill in the blank at LINE-3 with appropriate header for assignment (=) overload function.
• Fill in the blank at LINE-4 with an appropriate concatenation statement.
  The program must satisfy the sample input and output.
Your last recorded submission was on 2022-08-14, 14:07 IST
Select the Language for this assignment. 
1
#include<iostream>
#include<malloc.h>
#include<string.h>
using namespace std;
class Test{
    char *s;
public:
    Test(char *s) : s(s) {} //LINE-1

    ~Test(){ free(s); }           //LINE-2

    Test& operator=(Test &m){ //LINE-3

        free(s);
        s = strdup(m.s);
        return *this;
    }
    void update(char* x){
      strcat(strcat(s,{" "}),x);     //LINE-4
    }
0
    void print(){
1
        cout << s << endl;
2
    }
3
};
4
int main(){
5
    string str1, str2;
6
    cin >> str1 >> str2;
7
    Test *m1 = new Test(&str1[0]);
8
    Test *m2 = m1;
9
    m2->update(&str2[0]);
10
    m2->print();
11
    delete(m1);
12
    return 0;
13
}
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
Hello Sir
Hello Sir\n
Hello Sir\n
Passed
Test Case 2
Good Night
Good Night\n
Good Night\n
Passed


Private Test cases used for EvaluationStatus
Test Case 1
Passed




W3_Programming QS-3

Due on 2022-08-18, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
• at LINE-1 with appropriate declaration of data member z,
• at LINE-2 with appropriate constructor statement, and
• at LINE-3 and LINE-4 with appropriate header of the functions calcZ() and print(),
  such that it will satisfy the given test cases.
Your last recorded submission was on 2022-08-14, 18:12 IST
Select the Language for this assignment. 
1
#include<iostream>
using namespace std;
class Point3D {
    int x, y;
    mutable int z; // LINE-1

public:
    Point3D(int x_, int y_) : x(x_*x_),y(y_*y_) {} //LINE-2

    void calcZ() const { z = x * y; }; // LINE-3

    void print() const { // LINE-4
0
        cout << "(" << x << "," << y << "," << z << ")";
1
    }
2
};
3
4
int main() {
5
    int i, j;
6
    cin >> i >> j;
7
    const Point3D m(i, j);
8
    m.calcZ();
9
    m.print();
10
    return 0;
11
}
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
3 5
(9,25,225)
(9,25,225)
Passed
Test Case 2
10 -5
(100,25,2500)
(100,25,2500)
Passed






Private Test cases used for EvaluationStatus
Test Case 1
Wrong Answer



I will update the answer on telegram channel.
Join our Telegram Channel : https://telegram.me/SwayamSolver





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



W4_Programming QS-1

Due on 2022-08-25, 23:59 IST
Consider the program below which defines a class Database. Complete the program with the
following instructions.
• Fill in the blank at LINE-1 to complete the declaration of member variable ins.
• Fill in the blank at LINE-2 to specify the return type of createIns() function.
• Fill in the blank at LINE-3 to call the createIns() function with parameter i.
Your last recorded submission was on 2022-08-22, 19:08 IST
Select the Language for this assignment. 
1
#include<iostream>
using namespace std;
class Database{
    int id;
    static Database *ins;                   //LINE-1
    Database(int i) : id(i) {}
    public:
        int getIns(){ return id; }
        static Database* createIns(int i){      //LINE-2
            if(!ins)
                ins = new Database(i);
            return ins;
        }
        ~Database();
};
Database *Database::ins = 0;                
void fun(int i){
    Database *s = Database::createIns(i);   //LINE-3
    cout << s->getIns();
}
0
Database::~Database(){ cout << id; }
1
2
int main(){
3
    int a,b;
4
    cin >> a >> b;
5
    Database *s = Database::createIns(a);
6
    cout << s->getIns();
7
    fun(b);
8
    return 0;
9
}
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 5
44
44
Passed
Test Case 2
5 10
55
55
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed









W4_Programming QS-2

Due on 2022-08-25, 23:59 IST
Consider the following program.
• Fill in the blanks at LINE-1 to complete forward declaration.
• Fill in the blank at LINE-2 with appropriate function declaration so that function
calculate can access private data member of TotalAmount class.
The program must satisfy the sample input and output.
Your last recorded submission was on 2022-08-22, 19:08 IST
Select the Language for this assignment. 
1
#include<iostream>
using namespace std;

class Interest; //LINE-1
class TotalAmount{
    double prinAmt;
    double amt = 0;
public:
    TotalAmount(double p) : prinAmt(p){}
    double calculate(Interest&);
};
class Interest{
    double in;
public:
    Interest(double i) : in(i){ }

    friend double TotalAmount::calculate(Interest &i); //LINE-2
};
0
double TotalAmount::calculate(Interest &i){
1
    amt = prinAmt * (1 + i.in / 100);
2
    return amt;
3
}
4
int main(){
5
    double i, j;
6
    cin >> i >> j;
7
    TotalAmount m(i);
8
    Interest in(j);
9
    cout << "Matured Amount: " << m.calculate(in);
10
    return 0;
11
}
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
1000 5
Matured Amount: 1050
Matured Amount: 1050
Passed
Test Case 2
5000 8
Matured Amount: 5400
Matured Amount: 5400
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed




W4_Programming QS-3

Due on 2022-08-25, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
• at LINE-1 to complete operator overload function,
• at LINE-2 and LINE-3 to calculate subtraction of two position class.
such that it will satisfy the given test cases. 
Your last recorded submission was on 2022-08-22, 19:09 IST
Select the Language for this assignment. 
1
#include<iostream>
using namespace std;
class position{
    int x, y;
    public:
        position(int a, int b) : x(a), y(b) {}

        position operator-(const position& p1){ //LINE-1

            position p(0,0);

            p.x = this->x - p1.x; //LINE-2

            p.y = this->y - p1.y; //LINE-3

            return p;
        }
0
        void print(){ cout << "(" << x << ", " << y << ")"; }
1
2
};
3
4
5
int main(){
6
    int x1,y1,x2,y2;
7
    cin >> x1 >> y1 >> x2 >> y2;
8
    position p1(x1,y1), p2(x2,y2), p3(0,0);
9
    p3 = p1-p2;
10
    p3.print();
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 8 6 7
(-1, 1)
(-1, 1)
Passed
Test Case 2
6 7 2 5
(4, 2)
(4, 2)
Passed



Private Test cases used for EvaluationStatus
Test Case 1
Passed







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








W5_Programming QS-1

Due on 2022-09-01, 23:59 IST
Complete the program with the following instructions.
• Fill in the blank at LINE-1 to complete the inheritance statement for class Rectangle,
• Fill in the blanks at LINE-2 and LINE-3 to complete the return statement.
The program must satisfy the given test cases. 
Your last recorded submission was on 2022-08-27, 11:04 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
class Area{
4
    public:
5
        double getVal(int x, int y){ return (x*y); }
6
};
7
8
class Perimeter{
9
    public:
10
        double getVal(int x, int y){ return (2*(x+y)); }
11
};
12
class Rectangle : public Area, public Perimeter{ //LINE-1
    int x, y;
    public:
        Rectangle(int _x, int _y) : x(_x), y(_y){ }

        double getArea(){ return Area::getVal(x,y); } //LINE-2

        double getPerimeter(){ return Perimeter::getVal(x,y); } //LINE-3
};
0
int main(){
1
    int a, b;
2
    cin >> a >> b;
3
    Rectangle r(a,b);
4
    cout << r.getArea() << ", " << r.getPerimeter();
5
    return 0;
6
}
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 8
40, 26
40, 26
Passed
Test Case 2
2 5
10, 14
10, 14
Passed



Private Test cases used for EvaluationStatus
Test Case 1
Passed








W5_Programming QS-2

Due on 2022-09-01, 23:59 IST
Consider the following program with the following instructions.
• Fill in the blanks at LINE-1 to complete the inheritance statement
• Fill in the blank at LINE-2 to complete the constructor statement
The program must satisfy the sample input and output.
Your last recorded submission was on 2022-08-27, 11:04 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
class B1{
4
protected:
5
    int b1;
6
    public:
7
        B1(int b) : b1(b){}
8
};
9
class B2{
10
    protected:
11
        int b2;
12
    public:
13
        B2(int b) : b2(b){}
14
};
15
class D : public B1, public B2{ //LINE-1

    int d;
    public:
        D(int x) : d(x), B1(x+2), B2(x+4) {} //LINE-2
0
        void show(){
1
            cout << d << ", " << b1 << ", " << b2;
2
        }
3
};
4
5
6
int main(){
7
    int x;
8
    cin >> x;
9
    D t1(x);
10
    t1.show();
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
8
8, 10, 12
8, 10, 12
Passed
Test Case 2
5
5, 7, 9
5, 7, 9
Passed



Private Test cases used for EvaluationStatus
Test Case 1
Passed






W5_Programming QS-3

Due on 2022-09-01, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
• at LINE-1, LINE-2, and LINE-3 to complete the constructor initialization,
• at LINE-4, LINE-5, and LINE-6 to complete return statements,
such that it will satisfy the given test cases. 
Your last recorded submission was on 2022-08-27, 11:05 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
class Step{
4
    int a;
5
    public:
6
        Step(int _a = 0);
7
        int sum();
8
};
9
class Step1 : public Step{
10
    int b;
11
    public:
12
        Step1(int _a = 0, int _b = 0);
13
        int sum();
14
};
15
class Step2 : public Step1{
16
    int c;
17
    public:
18
        Step2(int _a = 0, int _b = 0, int _c = 0);
19
        int sum();
20
};
21
Step::Step(int _a) : a(_a) {} //LINE-1

Step1::Step1(int _a, int _b) : Step(_a), b(_b) {} //LINE-2

Step2::Step2(int _a, int _b, int _c) : Step1(_a, _b), c(_c) {} //LINE-3

int Step::sum(){ return a; } //LINE-4

int Step1::sum(){ return Step::sum()+b ; } //LINE-5

int Step2::sum(){ return Step1::sum()+c ; } //LINE-6
0
int main(){
1
    int a, b, c;
2
    cin >> a >> b >> c;
3
    Step aObj(a);
4
    Step1 bObj(a, b);
5
    Step2 cObj(a, b, c);
6
    cout << aObj.sum() << ", " << bObj.sum() << ", " <<     cObj.sum();
7
    return 0;
8
}
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 6 7
5, 11, 18
5, 11, 18
Passed
Test Case 2
10 20 30
10, 30, 60
10, 30, 60
Passed



Private Test cases used for EvaluationStatus
Test Case 1
Passed






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








W6_Programming QS-1

Due on 2022-09-08, 23:59 IST
Complete the program with the following instructions.
  • Fill in the blank at LINE-1 to complete the destructor declaration,
  • Fill in the blanks at LINE-2 to declare fun() as pure virtual function,
  • Fill in the blank at LINE-3 to complete the object initialization.
The program must satisfy the given test cases.
Your last recorded submission was on 2022-08-31, 08:53 IST
Select the Language for this assignment. 
1
#include<iostream>
#include<cstring>
using namespace std;
class Base{
protected:
    string s;
public:
    Base(string c) : s(c){}

    virtual ~Base(){ } //LINE-1

    virtual string fun(string x)=0; //LINE-2
};
class Derived : public Base{
public:
    Derived(string c) : Base(c) {}
    ~Derived();
    string fun(string x){
        return s+x;
    }
};
class Wrapper{
public:
    void fun(string a, string b){

        Base *t = new Derived(a); //LINE-3
        string i = t->fun(b);
        cout << i << " ";
        delete t;
    }
};
0
Derived::~Derived(){ cout << s << " "; }
1
int main(){
2
    string i, j;
3
    cin >> i >> j;
4
    Wrapper w;
5
    w.fun(i,j);
6
    return 0;
7
}
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
o k
ok o 
ok o 
Passed
Test Case 2
C ++
C++ C 
C++ C 
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed








W6_Programming QS-2

Due on 2022-09-08, 23:59 IST
Consider the following program with the following instructions.
  • Fill in the blank at LINE-1 to complete function declaration,
  • Fill in the blank at LINE-2 with appropriate statement so that global function caller()
can access private member function fun() of class hierarchy.
The program must satisfy the sample input and output.
Your last recorded submission was on 2022-08-31, 08:54 IST
Select the Language for this assignment. 
1
#include<iostream>
using namespace std;
class Base{
    int i;

    virtual void fun(); //LINE-1

public:
    Base(int x) : i(x) {}

    friend void caller(Base &t); //LINE-2
};
0
class Derived : public Base{
1
    int j;
2
    void fun(){ cout << j; }
3
public:
4
    Derived(int x) : Base(x), j(10*x){}
5
};
6
void Base::fun(){ cout << i; }
7
void caller(Base &t){
8
    t.fun();
9
}
10
int main(){
11
    int x;
12
    cin >> x;
13
    Derived t(x);
14
    caller(t);
15
    return 0;
16
}
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
8
80
80
Passed
Test Case 2
5
50
50
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed








W6_Programming QS-3

Due on 2022-09-08, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
  • Fill in the blanks at LINE-1 and LINE-2 with appropriate destructor declaration statements
such that it will satisfy the given test cases.
Your last recorded submission was on 2022-08-31, 08:55 IST
Select the Language for this assignment. 
1
#include<iostream>
using namespace std;
class Test{
protected:
    int n;
public:
    Test(int i) : n(i) { cout << ++n << " "; }

    virtual ~Test(); //Line-1
};

class DerivedTest : public Test{
public:

    virtual ~DerivedTest(); //Line-2
    DerivedTest(int i) : Test(2*i) { cout<< ++n << " "; }
};
0
Test::~Test() { cout<< --n << " "; }
1
2
DerivedTest::~DerivedTest() { cout<< --n << " "; }
3
4
int main(){
5
    int n;
6
    cin>>n;
7
    DerivedTest *d = new DerivedTest(n);
8
    Test *t = d;
9
    delete t;
10
    return 0;
11
}
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
11 12 11 10 
11 12 11 10 
Passed
Test Case 2
2
5 6 5 4 
5 6 5 4 
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
















































































































































































































No comments:

Post a Comment

Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.