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 Jan-2025 | Swayam

NPTEL Programming in Modern C++ Programming Assignment Jan-2025 | Swayam

 

NPTEL Â» Programming in Modern C++


  Please scroll down for latest Programs. ðŸ‘‡ 




W1_Programming Qs.1

Due on 2025-02-06, 23:59 IST
Select the Language for this assignment. 
1
#include <iostream>
2
#include <cmath>                //LINE-1 
3
using namespace std;
4
struct point{
5
    int x, y;
6
};
7
 
8
double get_len(point p1, point p2){
9
    return sqrt((p1.y - p2.y) * (p1.y - p2.y) + (p1.x - p2.x) * (p1.x - p2.x));    //LINE-2
10
}
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




W1_Programming Qs.2

Due on 2025-02-06, 23:59 IST
Select the Language for this assignment. 
1
#include <iostream>
2
#include <algorithm>
3
using namespace std;
4
 
5
bool max_str (string s1, string s2) {    //LINE-1
6
    return (s1 > s2);            //LINE-2
7
}
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 after ignoring Presentation Error
Test Case 2
Wale Fox Deer Frog Crab
Wale Frog Fox Deer Crab
Wale Frog Fox Deer Crab 
Passed after ignoring Presentation Error




W1_Programming Qs.3

Due on 2025-02-06, 23:59 IST
Select the Language for this assignment. 
1
#include <iostream>
2
#include <stack>
3
#include <vector>
4
 
5
void printReverseOrder(std::vector<std::string> words){
6
    std::stack<std::string> s;
7
    
8
    for(int i = 0; i < words.size(); i++)
9
         s.push(words[i]);             //LINE-1
10
    while(!s.empty()){
11
        std::cout << s.top() << " ";    //LINE-1
12
         s.pop();             //LINE-3                       
13
    }
14
}
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 after ignoring Presentation Error
Test Case 2
5 Arctic Antarctic Atlantic Pacific Indian
Indian Pacific Atlantic Antarctic Arctic
Indian Pacific Atlantic Antarctic Arctic 
Passed after ignoring Presentation Error





W2_Programing Qs.1

Due on 2025-02-06, 00:00 IST
Your last recorded submission was on 2025-02-04, 13:44 IST
Select the Language for this assignment. 
1
#include <iostream>
2
using namespace std;
3
 
4
struct point {
5
    int x, y;
6
};
7
 
8
point operator+(point pt, int t) {    //LINE-1
9
    point new_pt;       //LINE-2
10
    new_pt.x = pt.x + t;
11
    new_pt.y = pt.y + t;
12
    return new_pt;       //LINE-3
13
}
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



W2_Programing Qs.2

Due on 2025-02-06, 23:59 IST
Your last recorded submission was on 2025-02-04, 13:45 IST
Select the Language for this assignment. 
1
#include <iostream>
2
using namespace std;
3
 
4
 int product(int a, int b = 1, int c = 1) {
5
    return a * b * c;
6
}
7
 
8
double product(double a, double b) {
9
    return a * b;    
10
}
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



W2_Programing Qs.3

Due on 2025-02-06, 23:59 IST
Your last recorded submission was on 2025-02-04, 13:46 IST
Select the Language for this assignment. 
1
#include <iostream>
2
using namespace std;
3
 
4
void update_and_sum(int a,int b,int &c) {    //LINE-1
5
    a *= 10;
6
    b *= 10;
7
    c = a + b;
8
    cout << a << ", " << b << ", " << c << endl;
9
}
0
int main() {
1
    int i1, i2, i3 = 0;
2
    cin >> i1 >> i2;
3
    update_and_sum(i1, i2, i3);
4
    cout << i1 << ", " << i2 << ", " << i3 << endl;
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
10 20
100, 200, 300\n
10, 20, 300
100, 200, 300\n
10, 20, 300\n
Passed after ignoring Presentation Error
Test Case 2
-10 300
-100, 3000, 2900\n
-10, 300, 2900
-100, 3000, 2900\n
-10, 300, 2900\n
Passed after ignoring Presentation Error



W3_Programming-Qs.1

Due on 2025-02-13, 23:59 IST
Your last recorded submission was on 2025-02-12, 21:15 IST
Select the Language for this assignment. 
1
#include<iostream>
2
#include<cmath>
3
using namespace std;
4
class Complex{
5
    const int x,y;
6
public:
7
    Complex(int _x=0, int _y=0) : x(_x), y(_y) {} //LINE-1
8
    Complex(const Complex& c) : x(c.x), y(c.y) {} //LINE-2
9
    void sum(Complex p){
10
        int rx =  x+p.x; //LINE-3
11
        int ry = y+p.y; //LINE-4
12
        cout << "(" << rx << "," << ry << ")" << endl;
13
    }
14
    void print(){ cout << "(" << x << "," << y << ")" << endl; }
15
};
0
int main(){
1
    int x1,x2,y1,y2;
2
    cin >> x1 >> y1 >> x2 >> y2;
3
    Complex c1(x1,y1), c2(x2,y2);
4
    c1.print();
5
    c2.print();
6
    c1.sum(c2);
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
1 2 3 4
(1,2)\n
(3,4)\n
(4,6)
(1,2)\n
(3,4)\n
(4,6)\n
Passed after ignoring Presentation Error
Test Case 2
5 10 15 20
(5,10)\n
(15,20)\n
(20,30)
(5,10)\n
(15,20)\n
(20,30)\n
Passed after ignoring Presentation Error



W3_Programming_Qs.2

Due on 2025-02-13, 23:59 IST
Your last recorded submission was on 2025-02-12, 21:16 IST
Select the Language for this assignment. 
1
#include<iostream>
2
#include<malloc.h>
3
#include<string.h>
4
using namespace std;
5
class Test{
6
    char *s;
7
public:
8
    Test(char *s) : s(strdup(s)) {} //LINE-1
9
    ~Test(){ free(s); }           //LINE-2
10
    Test& operator=(const Test& m){ //LINE-3
11
        free(s);
12
        s = strdup(m.s);
13
        return *this;
14
    }
15
    void update(char* x){
16
        strcat(strcat(s," "),x);     //LINE-4
17
    }
18
    void print(){
19
        cout << s << endl;
20
    }
21
};
0
int main(){
1
    string str1, str2;
2
    cin >> str1 >> str2;
3
    Test *m1 = new Test(&str1[0]);
4
    Test *m2 = m1;
5
    m2->update(&str2[0]);
6
    m2->print();
7
    delete(m1);
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
Hello Sir
Hello Sir
Hello Sir\n
Passed after ignoring Presentation Error
Test Case 2
Good Night
Good Night
Good Night\n
Passed after ignoring Presentation Error



W3_Programming_Qs.3

Due on 2025-02-13, 23:59 IST
Your last recorded submission was on 2025-02-12, 21:16 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
class Point3D {
4
    int x, y;
5
    mutable int z; // LINE-1
6
public:
7
    Point3D(int x_, int y_) : x(x_* x_), y(y_* y_) { } //LINE-2
8
    void calcZ() const { z = x * y; }; // LINE-3
9
    void print() const { // LINE-4
10
        cout << "(" << x << "," << y << "," << z << ")";
11
    }
12
};
0
int main() {
1
    int i, j;
2
    cin >> i >> j;
3
    const Point3D m(i, j);
4
    m.calcZ();
5
    m.print();
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
3 5
(9,25,225)
(9,25,225)
Passed
Test Case 2
10 -5
(100,25,2500)
(100,25,2500)
Passed




W4_Programming-Qs.1

Due on 2025-02-20, 23:59 IST
Your last recorded submission was on 2025-02-13, 18:20 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
class Database{
4
    int id;
5
    static Database *ins;                   //LINE-1
6
    Database(int i) : id(i) {}
7
    public:
8
        int getIns(){ return id; }
9
        static Database* createIns(int i){      //LINE-2
10
            if(!ins)
11
                ins = new Database(i);
12
            return ins;
13
        }
14
        ~Database();
15
};
16
Database *Database::ins = 0;                
17
void fun(int i){
18
    Database *s = Database::createIns(i);   //LINE-3
19
    cout << s->getIns();
20
}
0
Database::~Database(){ cout << id; }
1
int main(){
2
    int a,b;
3
    cin >> a >> b;
4
    Database *s = Database::createIns(a);
5
    cout << s->getIns();
6
    fun(b);
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
4 5
44
44
Passed
Test Case 2
5 10
55
55
Passed



W4_Programming-Qs.2

Due on 2025-02-20, 23:59 IST
Your last recorded submission was on 2025-02-13, 18:21 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
class Interest; //LINE-1
4
class TotalAmount{
5
    double prinAmt;
6
    double amt = 0;
7
public:
8
    TotalAmount(double p) : prinAmt(p){}
9
    double calculate(Interest&);
10
};
11
class Interest{
12
    double in;
13
public:
14
    Interest(double i) : in(i){ }
15
     friend class TotalAmount; //LINE-2
16
};
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



W4_Programming-Qs.3

Due on 2025-02-20, 23:59 IST
Your last recorded submission was on 2025-02-13, 18:22 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
class position{
4
    int x, y;
5
    public:
6
        position(int a, int b) : x(a), y(b) {}
7
        position operator-(const position& p1){ //LINE-1
8
            position p(0,0);
9
            p.x = x - p1.x; //LINE-2
10
            p.y = y - p1.y; //LINE-3
11
            return p;
12
        }
13
        void print(){ cout << "(" << x << ", " << y << ")"; }
14
};
0
int main(){
1
    int x1,y1,x2,y2;
2
    cin >> x1 >> y1 >> x2 >> y2;
3
    position p1(x1,y1), p2(x2,y2), p3(0,0);
4
    p3 = p1-p2;
5
    p3.print();
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
5 8 6 7
(-1, 1)
(-1, 1)
Passed
Test Case 2
6 7 2 5
(4, 2)
(4, 2)
Passed



W5_Programming-Qs.1

Due on 2025-02-27, 23:59 IST
Your last recorded submission was on 2025-02-25, 20:46 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
class Perimeter{
8
    public:
9
        double getVal(int x, int y){ return (2*(x+y)); }
10
};
11
class Rectangle : public Area, public Perimeter{ //LINE-1
12
    int x, y;
13
    public:
14
        Rectangle(int _x, int _y) : x(_x), y(_y){ }
15
        double getArea(){ return Area::getVal(x,y); } //LINE-2
16
        double getPerimeter(){ return Perimeter::getVal(x,y); } //LINE-3
17
};
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



W5_Programming-Qs.2

Due on 2025-02-27, 23:59 IST
Your last recorded submission was on 2025-02-25, 20:47 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
16
    int d;
17
    public:
18
        D(int x) :  B1(x+2), B2(x+4), d(x) {} //LINE-2
19
        void show(){
20
            cout << d << ", " << b1 << ", " << b2;
21
        }
22
};
0
int main(){
1
    int x;
2
    cin >> x;
3
    D t1(x);
4
    t1.show();
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
8
8, 10, 12
8, 10, 12
Passed
Test Case 2
5
5, 7, 9
5, 7, 9
Passed



W5_Programming-Qs.3

Due on 2025-02-27, 23:59 IST
Your last recorded submission was on 2025-02-25, 20:48 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
22
 
23
Step1::Step1(int _a, int _b) : Step(_b), b(_a) {} //LINE-2
24
 
25
Step2::Step2(int _a, int _b, int _c) : Step1(_b,_c), c(_a) {} //LINE-3
26
 
27
int Step::sum(){ return a; } //LINE-4
28
 
29
int Step1::sum(){ return Step::sum() + b; } //LINE-5
30
 
31
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





W6_Programming_Qs.1

Due on 2025-03-06, 23:59 IST
Your last recorded submission was on 2025-02-27, 16:34 IST
Select the Language for this assignment. 
1
#include<iostream>
2
#include<cstring>
3
using namespace std;
4
class Base{
5
protected:
6
    string s;
7
public:
8
    Base(string c) : s(c){}
9
    virtual ~Base(){ } //LINE-1
10
    virtual string fun(string x) = 0; //LINE-2
11
};
12
class Derived : public Base{
13
public:
14
    Derived(string c) : Base(c) {}
15
    ~Derived();
16
    string fun(string x){
17
        return s+x;
18
    }
19
};
20
class Wrapper{
21
public:
22
    void fun(string a, string b){
23
        Base *t = new Derived(a); //LINE-3
24
        string i = t->fun(b);
25
        cout << i << " ";
26
        delete t;
27
    }
28
};
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 after ignoring Presentation Error
Test Case 2
C ++
C++ C
C++ C 
Passed after ignoring Presentation Error



W6_Programming_Qs.2

Due on 2025-03-06, 23:59 IST
Your last recorded submission was on 2025-02-27, 16:35 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
class Base{
4
    int i;
5
    virtual void fun(); //LINE-1
6
 
7
public:
8
    Base(int x) : i(x) {}
9
    friend void caller(Base &t); //LINE-2
10
};
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



W6_Programming_Qs.3

Due on 2025-03-06, 23:59 IST
Your last recorded submission was on 2025-02-27, 16:38 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
class Test{
4
protected:
5
    int n;
6
public:
7
    Test(int i) : n(i) { cout << ++n << " "; }
8
 
9
    virtual ~Test(); //Line-1
10
};
11
 
12
class DerivedTest : public Test{
13
public:
14
    ~DerivedTest(); //Line-2
15
 
16
    DerivedTest(int i) : Test(2*i) { cout<< ++n << " "; }
17
};
0
Test::~Test() { cout<< --n << " "; }
1
DerivedTest::~DerivedTest() { cout<< --n << " "; }
2
int main(){
3
    int n;
4
    cin>>n;
5
    DerivedTest *d = new DerivedTest(n);
6
    Test *t = d;
7
    delete t;
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
5
11 12 11 10
11 12 11 10 
Passed after ignoring Presentation Error
Test Case 2
2
5 6 5 4
5 6 5 4 
Passed after ignoring Presentation Error




W7_Programming_Qs.1

Due on 2025-03-13, 23:59 IST
Your last recorded submission was on 2025-03-12, 19:38 IST
Select the Language for this assignment. 
1
#include <iostream>
2
using namespace std;
3
class IP1 {
4
    int i;
5
    public:
6
        IP1(int ai) : i(ai) {}
7
        int get() const { return i; }
8
        void update() { i *= 10; }
9
    };
10
    class IP2 {
11
        int i;
12
        public:
13
            IP2(int ai) : i(ai) {}
14
            int get() const { return i; }
15
            IP2(IP1& a) : i(a.get()) {} //LINE-1
16
            operator IP1() { return IP1(i); } //LINE-2
17
            void update() { i *= 20; }
18
    };
0
int main() {
1
    int i;
2
    cin >> i;
3
    IP1 a(i+2);
4
    IP2 b(i);
5
    const IP2 &r = static_cast<IP2>(a);
6
    a.update();
7
    cout << a.get() << ":";    
8
    cout << r.get() << ":";
9
    const IP1 &s = static_cast<IP1>(b);
10
    b.update();
11
    cout << b.get() << ":";
12
    cout << s.get() << ":";
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
2
40:4:40:2:
40:4:40:2:
Passed
Test Case 2
5
70:7:100:5:
70:7:100:5:
Passed



W7_Programming_Qs.2

Due on 2025-03-13, 23:59 IST
Your last recorded submission was on 2025-03-12, 19:39 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
class myClassA{
4
    int a = 5;
5
    public:
6
        void print(){
7
            cout << a << " ";
8
        }
9
};
10
class myClassB{
11
    int b = 10;
12
    public:
13
        void print(){
14
            cout << b;
15
        }
16
        void operator=(int x){ //LINE-1
17
            b = b * x;
18
        }
19
};
20
void fun(const myClassA &t){
21
    int x;
22
    cin >> x;
23
    myClassA &u =  const_cast<myClassA&>(t); //LINE-2
24
    u.print();
25
    myClassB &v = reinterpret_cast<myClassB&>(u); //LINE-3
26
    v = x;
27
    v.print();
28
}
0
int main(){
1
    myClassA t1;
2
    fun(t1);
3
    return 0;
4
}
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 25
5 25
Passed
Test Case 2
7
5 35
5 35
Passed



W7_Programming_Qs.3

Due on 2025-03-13, 23:59 IST
Your last recorded submission was on 2025-03-12, 19:40 IST
Select the Language for this assignment. 
1
#include<iostream>
2
#include<cstring>
3
#include<malloc.h>
4
using namespace std;
5
class String{
6
    char* _str;
7
public:
8
    String(char* str) : _str(str){} //LINE-1
9
    operator char*(){ //LINE-2
10
        char* t_str = (char*)malloc(sizeof(_str) + 7);
11
        strcpy(t_str, "Welcome ");
12
        strcat(t_str, _str);
13
        return t_str;
14
    }
15
};
0
int main(){
1
    char s[15];
2
    cin >> s;
3
    String st = static_cast<String>(s);
4
    cout << static_cast<char*>(st);
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
Amal
Welcome Amal
Welcome Amal
Passed
Test Case 2
Som
Welcome Som
Welcome Som
Passed




W8_Programming_Qs.1

Due on 2025-03-20, 23:59 IST
Select the Language for this assignment. 
1
#include<iostream>
2
#include<vector>
3
using namespace std;
4
 
5
template<class T>    //LINE-1
6
class Filter{
7
    T ub, lb;
8
    public:
9
        Filter(T _lb = 0, T _ub = 0) : ub(_ub), lb(_lb) { }
10
        vector<T> extract(vector<T> tVec);
11
};
12
template<class T> vector<T> Filter<T>::extract(vector<T> tVec) {    //LINE-2
13
    vector<T> rVec;
14
    for(int i = 0; i < tVec.size(); i++){
15
        if(tVec[i] <= ub && tVec[i] >= lb)
16
            rVec.push_back(tVec[i]);
17
    }
18
    return rVec;
19
}
0
int main(){
1
    int i1, i2;
2
    char d1, d2;
3
    cin >> i1 >> i2 >> d1 >> d2;
4
    Filter<int> flt1(i1, i2);
5
    Filter<char> flt2(d1, d2);
6
    int arr1[] = {30, 10, 50, 60, 80, 20, 40, 70, 90};
7
    char arr2[] = {'a', 'n', 'i', 'm', 'l', 's'};
8
    vector<int> iVec(arr1, arr1 + 9);
9
    vector<char> cVec(arr2, arr2 + 6);
10
    vector<int> rVec1 = flt1.extract(iVec);
11
    vector<char> rVec2 = flt2.extract(cVec);
12
    for(int i = 0; i < rVec1.size(); i++)
13
        cout << rVec1[i] << ", ";
14
    cout << endl;
15
    for(int i = 0; i < rVec2.size(); i++)
16
        cout << rVec2[i] << ", ";
17
    return 0;
18
}
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
30 50 f x
30, 50, 40, \n
n, i, m, l, s,
30, 50, 40, \n
n, i, m, l, s, 
Passed after ignoring Presentation Error
Test Case 2
30 60 m s
30, 50, 60, 40, \n
n, m, s,
30, 50, 60, 40, \n
n, m, s, 
Passed after ignoring Presentation Error



W8_Programming_Qs.2

Due on 2025-03-20, 23:59 IST
Select the Language for this assignment. 
1
#include<iostream>
2
#include<exception>
3
#include<vector>
4
#include<cstdlib>
5
using namespace std;
6
class InvalidAccess : public exception { // LINE-1
7
    public:
8
        virtual const char* what() const throw() {
9
            return "invalid access";    //LINE-2
10
        }
11
};
12
template<class T>
13
class ItemList{
14
    int n;
15
    T* items;    //LINE-3
16
    public:
17
        ItemList(vector<T> _items) : n(_items.size()), 
18
                       items((T*)malloc(n * sizeof(int))){
19
            for(int i = 0; i < n; i++){
20
                items[i] = _items[i];
21
            }
22
        }
23
        
24
        T& operator[](int i){     //LINE-4
25
            if(i >= 0 && i < n){
26
                return items[i];
27
            }
28
            throw InvalidAccess();      //LINE-5
29
        }
30
};
0
int main(){
1
    int idx[3];
2
    for(int i = 0; i < 3; i++){
3
        cin >> idx[i];
4
    }
5
    
6
    vector<int> iVec;
7
    vector<char> cVec;
8
    for(int i = 0; i < 5; i++){
9
        iVec.push_back((i + 1) * 10);
10
        cVec.push_back(65 + i);
11
    }
12
    
13
    ItemList<int> iList(iVec);
14
    ItemList<char> cList(cVec);
15
    
16
    for(int i = 0; i < 3; i++){
17
        try{
18
            cout << iList[idx[i]] << ", ";
19
            cout << cList[idx[i]] << endl;
20
        }catch(InvalidAccess e){
21
            cout << e.what() << endl;
22
        }
23
    }
24
    return 0;
25
}
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 6
30, C\n
invalid access\n
invalid access
30, C\n
invalid access\n
invalid access\n
Passed after ignoring Presentation Error
Test Case 2
2 4 6
30, C\n
50, E\n
invalid access
30, C\n
50, E\n
invalid access\n
Passed after ignoring Presentation Error



W8_Programming_Qs.3

Due on 2025-03-20, 23:59 IST
Select the Language for this assignment. 
1
#include <iostream>
2
#include <algorithm>
3
#include <string>
4
#include <vector>
5
using namespace std;
6
struct less_mag {
7
    bool operator()(string x, string y) {    //LINE-1
8
 
9
        return (x.length() < y.length()) ;    //LINE-2
10
    }
11
};
0
int main(){
1
    vector<string> iVec;
2
    int n;
3
    string na;
4
    cin >> n;
5
    for(int i = 0; i < n; i++){
6
        cin >> na;
7
        iVec.push_back(na);
8
    }
9
    sort(iVec.begin(), iVec.end(), less_mag());
10
    for(int i = 0; i < iVec.size(); i++)
11
        cout << iVec[i] << " ";
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
4 Ducks Chicken Dove Pig
Pig Dove Ducks Chicken
Pig Dove Ducks Chicken 
Passed after ignoring Presentation Error
Test Case 2
5 grapes figs jackfruit apple blueberries
figs apple grapes jackfruit blueberries
figs apple grapes jackfruit blueberries 
Passed after ignoring Presentation Error



W9_Programming-Qs.1

Due on 2025-03-27, 23:59 IST
Select the Language for this assignment. 
1
#include <iostream>
2
#include <map>
3
#include <string>
4
using namespace std;
5
 
6
map<string, int> merge_order(map<string, int> od1, map<string, int> od2){
7
    map<string, int> final_od;
8
    for (map<string, int>::iterator it = od1.begin(); it != od1.end(); ++it)   
9
        final_od[it->first] = od1[it->first];    //LINE-1
10
    for (map<string, int>::iterator it = od2.begin(); it != od2.end(); ++it)   
11
        final_od[it->first] += od2[it->first];    //LINE-2
12
    return final_od;
13
}
0
void show(map<string, int> od){
1
    for (map<string, int>::iterator it = od.begin(); it != od.end(); ++it)    
2
        cout << it->first << " => " << it->second << endl;
3
}
4
 
5
int main() { 
6
    map<string, int> order1;
7
    map<string, int> order2;
8
    string item;
9
    int qty;
10
    for(int i = 0; i < 3; i++){
11
        cin >> item >> qty;
12
        order1[item] = qty;
13
    }
14
    for(int i = 0; i < 3; i++){
15
        cin >> item >> qty;
16
        order2[item] = qty;
17
    }
18
    
19
    map<string, int> final_order = merge_order(order1, order2); 
20
    show(final_order);  
21
    return 0;
22
}
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
pen 2
mobile 1
cap 4
file 2
pen 4
mobile 1
cap => 4\n
file => 2\n
mobile => 2\n
pen => 6
cap => 4\n
file => 2\n
mobile => 2\n
pen => 6\n
Passed after ignoring Presentation Error
Test Case 2
paper 10
pen 1
book 2
paper 5
pencil 2
file 1
book => 2\n
file => 1\n
paper => 15\n
pen => 1\n
pencil => 2
book => 2\n
file => 1\n
paper => 15\n
pen => 1\n
pencil => 2\n
Passed after ignoring Presentation Error



W9_Programming-Qs.2

Due on 2025-03-27, 23:59 IST
Select the Language for this assignment. 
1
#include<iostream>
2
#include<string>
3
#include<algorithm>
4
#include<vector>
5
using namespace std;
6
 
7
class employee{
8
    private:
9
        string name;
10
        double salary;
11
    public:
12
        employee(string _name, double _salary) : name(_name), salary(_salary){}
13
        string getName() const{
14
            return name;
15
        }
16
        double getSalary() const{
17
            return salary;
18
        }
19
        friend ostream& operator<<(ostream& os, const employee& e);
20
};
21
 
22
ostream& operator<<(ostream& os, const employee& e){
23
    os << e.name << '-' << e.salary << endl;
24
    return os;
25
}
26
struct compareByName{
27
    bool operator()(const employee& e1, const employee& e2) const {
28
      return e1.getName() < e2.getName();
29
      }
30
};
31
 
32
struct compareBySalary{
33
    bool operator()(const employee& e1, const employee& e2) const {
34
      return e1.getSalary() < e2.getSalary();
35
      }
36
};
0
int main() {
1
    int n;              //number of employees
2
    cin >> n;
3
    vector<employee> emps;
4
    for(int i = 0; i < n; i++){
5
        string na;
6
        double sa;
7
        cin >> na >> sa;    //employee's name and salary
8
        employee e(na, sa);
9
        emps.push_back(e);
10
    }
11
    int t;              //sort option
12
    cin >> t;
13
    if(t == 1)
14
        sort(emps.begin(), emps.end(), compareByName());
15
    else if(t == 2)
16
        sort(emps.begin(), emps.end(), compareBySalary());
17
    for(vector<employee>::iterator p = emps.begin(); p != emps.end(); p++){
18
        cout << *p;
19
    }
20
    return 0;
21
}
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
deep 20000
riya 15000
vinay 18000
nilima 22000
2
riya-15000\n
vinay-18000\n
deep-20000\n
nilima-22000
riya-15000\n
vinay-18000\n
deep-20000\n
nilima-22000\n
Passed after ignoring Presentation Error
Test Case 2
5
kamal 23000
rahul 18000
vinita 20000
anuska 17000
rabin 15000
1
anuska-17000\n
kamal-23000\n
rabin-15000\n
rahul-18000\n
vinita-20000
anuska-17000\n
kamal-23000\n
rabin-15000\n
rahul-18000\n
vinita-20000\n
Passed after ignoring Presentation Error



W9_Programming-Qs.3

Due on 2025-03-27, 23:59 IST
Your last recorded submission was on 2025-03-16, 22:23 IST
Select the Language for this assignment. 
1
#include<iostream>
2
#include<vector>
3
using namespace std;
4
 
5
template<class T>
6
struct Filter{
7
    T ub, lb;
8
    Filter(T _lb = 0, T _ub = 0) : ub(_ub), lb(_lb) { }
9
    bool operator()(T i){ return (i <= ub && i >= lb); }    
10
};
11
template<class T, class Pred>     //LINE-1
12
 
13
T find_if(T first, T last, Pred pred) {
14
 
15
    while (first != last && !pred(*first)) ++first;    //LINE-2
16
 
17
        return first;
18
}
19
 
20
 
21
void printAllFiltered(vector<int> iVec, int lb, int ub){
22
    Filter<int> f(lb, ub);
23
    vector<int>::iterator p = find_if(iVec.begin(), iVec.end(), f);    //LINE-3
24
    while(p != iVec.end()){
25
        cout << *p << " ";
26
        p = find_if(++p, iVec.end(), f);
27
    }
28
}
0
int main(){
1
    vector<int> iVec {7, 8, 1, 4, 2, 5, 6, 3};
2
    int l, u;
3
    cin >> l >> u;
4
    printAllFiltered(iVec, l, u);
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 9
7 8 5 6
7 8 5 6 
Passed after ignoring Presentation Error
Test Case 2
3 7
7 4 5 6 3
7 4 5 6 3 
Passed after ignoring Presentation Error




W10_Programming_Qs.1

Due on 2025-04-03, 23:59 IST
Your last recorded submission was on 2025-03-24, 07:17 IST
Select the Language for this assignment. 
1
#include <iostream>
2
#include <list>
3
namespace Ver1{
4
    namespace Ver1_1 {    //LINE-1
5
        int addAll(std::list<int> i_list){
6
            int sum = 0;
7
            for(auto i : i_list){
8
                sum += i;
9
            }
10
            return sum;
11
        }
12
    }
13
     inline namespace Ver1_2 {    //LINE-2
14
        template<typename T>
15
        T addAll(std::list<T> t_list){
16
            T sum = 0;
17
            for(auto i : t_list){
18
                sum += i;
19
            }
20
            return sum;
21
        }
22
    }
23
}
24
 
25
using namespace Ver1 ;    //LINE-3
0
int main(){
1
    int n;
2
    std::cin >> n;
3
    std::list<int> ilist;
4
    std::list<double> dlist;
5
    for(int i = 0; i < n; i++){
6
        int x;
7
        std::cin >> x;
8
        ilist.push_back(x);
9
    }
10
    for(int i = 0; i < n; i++){
11
        double x;
12
        std::cin >> x;
13
        dlist.push_back(x);
14
    }
15
    std::cout << Ver1_1::addAll(ilist) << " ";
16
    std::cout << addAll(ilist) << " ";
17
    std::cout << addAll(dlist);
18
    return 0;
19
}
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
2 4 6
2.1 3.4 5.2
12 12 10.7
12 12 10.7
Passed
Test Case 2
5
3 9 4 8 3
4.3 2.5 6.5 1.2 7.4
27 27 21.9
27 27 21.9
Passed



W10_Programming_Qs.2

Due on 2025-04-03, 23:59 IST
Your last recorded submission was on 2025-03-24, 07:18 IST
Select the Language for this assignment. 
1
#include <iostream>
2
int getNumber(char c){
3
    return int(c);
4
}
5
int getNumber(double d){
6
    return int(d);
7
}
8
double getNumber(int i){
9
    return double(i);
10
}
11
 
12
template<typename T, typename U>    //LINE-1
13
 
14
decltype(auto) divide(T n1, U n2) {   //LINE-2
15
    return getNumber(n1) / getNumber(n2);
16
}
0
int main(){
1
    int a;
2
    double b;
3
    char c;
4
    std::cin >> a >> b >> c;
5
    std::cout << divide(c, a) << " ";
6
    std::cout << divide(c, b);
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 2.0 A
6.5 32
6.5 32
Passed
Test Case 2
5 5.0 B
13.2 13
13.2 13
Passed



W10_Programming_Qs.3

Due on 2025-04-03, 23:59 IST
Your last recorded submission was on 2025-03-24, 07:20 IST
Select the Language for this assignment. 
1
#include <iostream>
2
class point { 
3
    public:
4
        point(int x = 0, int y = 0) : _px(new int(x)), _py(new int(x)) { } 
5
        point(const point& p) : _px(new int(*(p._px) * 2)), 
6
                                   _py(new int(*(p._py) * 2)) { }  
7
        point& operator=(const point& p) {   
8
        if (this != &p) { 
9
            delete _px;
10
            delete _py;
11
            _px = new int(*(p._px) * 3);
12
            _py = new int(*(p._py) * 3);
13
        } 
14
        return *this;
15
    }
16
    ~point() { delete _px; delete _py; } 
17
    point(point&& p) noexcept : _px(p._px), _py(p._py) {
18
        //code-segment-1
19
      *_px *= 4;
20
      *_py *= 4;
21
      p._px = nullptr;
22
      p._py = nullptr;
23
    }   
24
    point& operator=(point&& p) noexcept{
25
        //code-segment-2
26
      if (this != &p) {
27
      delete _px;
28
      delete _py;
29
      _px = p._px;
30
      _py = p._py;
31
      *_px *= 5;
32
      *_py *= 5;
33
      p._px = nullptr;
34
      p._py = nullptr;
35
      }
36
      return *this;
37
    }
38
    friend std::ostream& operator<<(std::ostream& os, const point& p) { 
39
        std::cout << "(" << *(p._px) << ", " << *(p._py) << ")";
40
        return os;
41
    }
42
    friend std::istream& operator>>(std::istream& os, point& p) { 
43
        std::cin >> *(p._px) >> *(p._py);
44
        return os;
45
    }
46
    private:
47
        int *_px = nullptr, *_py = nullptr; 
48
};
0
int main(){
1
    point p1;
2
    std::cin >> p1;
3
    point p2 = p1;
4
    point p3;
5
    p3 = p1;
6
    std::cout << p1 << ", " << p2 << ", " << p3 << std::endl;
7
    
8
    point p4 = std::move(p1);
9
    std::cout << p4 << ", ";
10
    point p5;
11
    p5 = std::move(p4);
12
    std::cout << p5;
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
10 10
(10, 10), (20, 20), (30, 30)\n
(40, 40), (200, 200)
(10, 10), (20, 20), (30, 30)\n
(40, 40), (200, 200)
Passed
Test Case 2
1 2
(1, 2), (2, 4), (3, 6)\n
(4, 8), (20, 40)
(1, 2), (2, 4), (3, 6)\n
(4, 8), (20, 40)
Passed



W11_Programming_Qs.1

Due on 2025-04-10, 23:59 IST
Your last recorded submission was on 2025-04-09, 21:22 IST
Select the Language for this assignment. 
1
#include <iostream>
2
class person{
3
    public:
4
        virtual void show() = 0;
5
};
6
 
7
class Employee : public person {
8
    private:
9
        double salary;
10
    public:
11
        Employee(const double& _salary) : salary(_salary){ 
12
            std::cout << "lvalue" << " "; 
13
        }
14
        Employee(double&& _salary) : salary(_salary){
15
            std::cout << "rvalue" << " "; 
16
        }
17
        void show(){ std::cout << salary << " "; }
18
};
19
 
20
class Player : public person {
21
    private:
22
        int rank;
23
    public:
24
        Player(const int& _rank) : rank(_rank){
25
            std::cout << "lvalue" << " "; 
26
        }
27
        Player(int&& _rank) : rank(_rank){ 
28
            std::cout << "rvalue" << " "; 
29
        }
30
        void show(){ std::cout << rank << " "; }
31
};
32
template<typename T, typename U>        //LINE-1
33
 
34
T createPerson(U&& param){         //LINE-2
35
 
36
    return T(std::forward<U>(param));     //LINE-3
37
}
0
int main() {
1
    double s; 
2
    int r;
3
    std::cin >> s >> r;
4
    
5
    auto p1 = createPerson<Employee>(s);
6
    auto p2 = createPerson<Employee>(std::move(s));
7
    auto p3 = createPerson<Player>(r);
8
    auto p4 = createPerson<Player>(std::move(r));
9
    std::cout << std::endl;
10
    p1.show();
11
    p2.show();
12
    p3.show();
13
    p4.show();
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
10000.5 10
lvalue rvalue lvalue rvalue \n
10000.5 10000.5 10 10
lvalue rvalue lvalue rvalue \n
10000.5 10000.5 10 10 
Passed after ignoring Presentation Error
Test Case 2
50000 3
lvalue rvalue lvalue rvalue \n
50000 50000 3 3
lvalue rvalue lvalue rvalue \n
50000 50000 3 3 
Passed after ignoring Presentation Error



W11_Programming_Qs.2

Due on 2025-04-10, 23:59 IST
Your last recorded submission was on 2025-04-09, 21:24 IST
Select the Language for this assignment. 
1
#include <iostream>
2
template<typename T>
3
class Data{
4
    private:
5
        T _d;
6
    public:
7
        Data(T data) : _d(data){}
8
        T getData() const{
9
            return _d;
10
        }
11
};
12
 
13
template<typename T, typename U>
14
struct Adder{
15
    U operator()(std::ostream& os, Data<T>&& d1, Data<U>&& d2){
16
        os << "rvalue version: ";
17
        return (d1.getData() + d2.getData());
18
    }
19
    U operator()(std::ostream& os, const Data<T>& d1, const Data<U>& d2){
20
        os << "lvalue version: ";
21
        return (d1.getData() + d2.getData());
22
    }
23
};
24
template<typename F, typename... T>    //LINE-1 
25
 
26
decltype(auto) apply(std::ostream& os, F&& func, T&&... args) {    //LINE-2
27
 
28
    return func(os, std::forward<T>(args)...);    //LINE-3
29
}
0
int main() {
1
    int i;
2
    double d;
3
    std::cin >> i >> d;
4
    Data<int> d1(i);
5
    Data<double> d2(d);
6
    
7
    std::cout << apply(std::cout, Adder<int, double>(), d1, d2);
8
    std::cout << std::endl;
9
    std::cout << apply(std::cout, Adder<int, double>(), std::move(d1), std::move(d2));
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 15.5
lvalue version: 25.5\n
rvalue version: 25.5
lvalue version: 25.5\n
rvalue version: 25.5
Passed
Test Case 2
-1 5.3
lvalue version: 4.3\n
rvalue version: 4.3
lvalue version: 4.3\n
rvalue version: 4.3
Passed



W11_Programming_Qs.3

Due on 2025-04-10, 23:59 IST
Your last recorded submission was on 2025-04-09, 21:25 IST
Select the Language for this assignment. 
1
#include <iostream>
2
    #include <vector>
3
    #include <functional>
4
     
5
    int main(){
6
        std::function<int(std::vector<int>, int)> RecMin;    //LINE-1
7
 
8
        RecMin = [&RecMin](std::vector<int> tVec, int n) -> int {   //LINE-2
9
            return n == 1 ? tVec[0] : tVec[n - 1] < RecMin(tVec, n - 1) ? 
10
                tVec[n - 1] : RecMin(tVec, n - 1); 
11
        };
0
auto Print = [&RecMin](std::vector<int> tVec) {
1
            std::cout << RecMin(tVec, tVec.size()); 
2
        };
3
        int n, m;
4
        std::vector<int> vec;
5
        std::cin >> n;
6
        for(int i = 0; i < n; i++){
7
            std::cin >> m;
8
            vec.push_back(m);
9
        }
10
        Print(vec);
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
6
9 3 6 2 1 7
1
1
Passed
Test Case 2
5
10 -20 30 -40 50
-40
-40
Passed




W12_Programming_Qs.1

Due on 2025-04-17, 23:59 IST
Your last recorded submission was on 2025-04-17, 20:10 IST
Select the Language for this assignment. 
1
#include <iostream>       
2
#include <functional>     
3
#include <thread>         
4
#include <future>         
5
#include <vector>
6
 
7
void product (std::promise<long>& p, std::future<std::vector<int>>& f) {    
8
    std::vector<int> v = f.get();       
9
    long result = 1;
10
    for(int i : v)
11
        result *= (long)i;
12
    p.set_value(result);
13
}
14
int main () {
15
    std::promise<std::vector<int>> p1;    //LINE-1
16
 
17
    std::future<std::vector<int>> f1 = p1.get_future();    //LINE-2
18
    
19
    std::promise<long> p2;    //LINE-3
20
 
21
    std::future<long> f2 = p2.get_future();    //LINE-4
22
    
23
    std::thread th (product, std::ref(p2), std::ref(f1));    //LINE-5
0
int n, a;
1
    std::cin >> n;
2
    std::vector<int> v;
3
    for(int i = 0; i < n; i++){
4
        std::cin >> a;
5
        v.push_back(a);
6
    }
7
    
8
    p1.set_value (v);
9
    std::cout << f2.get();
10
    th.join();
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
3 10 20 30
6000
terminate called after throwing an instance of 'std::system_error'\n
  what():  Resource temporarily unavailable
Runtime Error
Test Case 2
4 10 -10 20 20
-40000
terminate called after throwing an instance of 'std::system_error'\n
  what():  Resource temporarily unavailable
Runtime Error




W12_Programming_Qs.1

Due on 2025-04-17, 23:59 IST
Your last recorded submission was on 2025-04-17, 20:10 IST
Select the Language for this assignment. 
1
#include <iostream>       
2
#include <functional>     
3
#include <thread>         
4
#include <future>         
5
#include <vector>
6
 
7
void product (std::promise<long>& p, std::future<std::vector<int>>& f) {    
8
    std::vector<int> v = f.get();       
9
    long result = 1;
10
    for(int i : v)
11
        result *= (long)i;
12
    p.set_value(result);
13
}
14
int main () {
15
    std::promise<std::vector<int>> p1;    //LINE-1
16
 
17
    std::future<std::vector<int>> f1 = p1.get_future();    //LINE-2
18
    
19
    std::promise<long> p2;    //LINE-3
20
 
21
    std::future<long> f2 = p2.get_future();    //LINE-4
22
    
23
    std::thread th (product, std::ref(p2), std::ref(f1));    //LINE-5
0
int n, a;
1
    std::cin >> n;
2
    std::vector<int> v;
3
    for(int i = 0; i < n; i++){
4
        std::cin >> a;
5
        v.push_back(a);
6
    }
7
    
8
    p1.set_value (v);
9
    std::cout << f2.get();
10
    th.join();
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
3 10 20 30
6000
terminate called after throwing an instance of 'std::system_error'\n
  what():  Resource temporarily unavailable
Runtime Error
Test Case 2
4 10 -10 20 20
-40000
terminate called after throwing an instance of 'std::system_error'\n
  what():  Resource temporarily unavailable
Runtime Error




W12_Programming_Qs.2

Due on 2025-04-17, 23:59 IST
Your last recorded submission was on 2025-04-17, 20:12 IST
Select the Language for this assignment. 
1
#include <iostream>
2
#include <vector>
3
#include <thread>
4
#include <functional>
5
#include <chrono>
6
#include <mutex>
7
 std::mutex mq_mutex;    //LINE-1  
8
 
9
class MessageQueue{
10
    private:
11
        int total_elems;
12
        int n;
13
    public:
14
        MessageQueue() : total_elems(0) {}
15
        void enqueue(int num_elems){
16
            std::unique_lock<std::mutex> lck(mq_mutex);    //LINE-2
17
            n = num_elems;
18
            int delay = (int)((double)std::rand() / (double)(RAND_MAX)* 10);
19
            std::this_thread::sleep_for(std::chrono::milliseconds(delay));
20
            total_elems += n;
21
        }
22
        void dequeue(int num_elems){ 
23
            std::unique_lock<std::mutex> lck(mq_mutex);    //LINE-3
24
            n = num_elems;
25
            int delay = (int)((double)std::rand() / (double)(RAND_MAX)* 10);
26
            std::this_thread::sleep_for(std::chrono::milliseconds(delay));
27
            total_elems -= n;
28
        }
29
        int getElemsCount(){
30
            return total_elems;
31
        }
32
};
0
void sender(MessageQueue& mq, int n){
1
    for(int i = 0; i < n; i++){
2
        int delay = (int)((double)std::rand() / (double)(RAND_MAX)* 10);
3
        std::this_thread::sleep_for(std::chrono::milliseconds(delay));
4
        mq.enqueue(i + 1);
5
    }
6
}
7
 
8
void receiver(MessageQueue& mq, int n){
9
    for(int i = n - 1; i >= 0; i--){
10
        int delay = (int)((double)std::rand() / (double)(RAND_MAX)* 30);
11
        std::this_thread::sleep_for(std::chrono::milliseconds(delay));
12
        mq.dequeue(i + 1);
13
    }
14
}
15
 
16
int main(){
17
    int n, m;
18
    std::cin >> n;
19
    std::cin >> m;
20
    MessageQueue mq;
21
    std::thread t1{ std::bind(sender, std::ref(mq), n) };
22
    std::thread t2{ std::bind(receiver, std::ref(mq), m) };
23
    
24
    t1.join();
25
    t2.join();
26
    std::cout << mq.getElemsCount();
27
    return 0;
28
}
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
0
terminate called after throwing an instance of 'std::system_error'\n
  what():  Resource temporarily unavailable
Runtime Error
Test Case 2
20 10
155
terminate called after throwing an instance of 'std::system_error'\n
  what():  Resource temporarily unavailable
Runtime Error




W12_Programming_Qs.3

Due on 2025-04-17, 23:59 IST
Your last recorded submission was on 2025-04-17, 20:13 IST
Select the Language for this assignment. 
1
#include <iostream>
2
#include <future>
3
#include <cmath>
4
using namespace std;
5
 
6
struct NthPrime{
7
    const long long n;
8
    NthPrime(const long long& n) : n( n) { }
9
    bool isPrime(long long n){
10
        if (n <= 1)
11
            return false;
12
        for (int i = 2; i <= sqrt(n); i++)
13
            if (n % i == 0)
14
                return false;
15
 
16
        return true;
17
    }
18
    long long operator()() {     //LINE-1
19
        long long num = 2;
20
        for(int i = 0; i < n; num++) {
21
            if (isPrime(num)) {
22
                ++i;
23
            }
24
        }
25
        return num-1;
26
    }
27
};
28
 
29
long long findNthPrime(int n){
30
    auto a = async(NthPrime(n)) ;    //LINE-2
31
    return a.get() ;                  //LINE-3    
32
}
0
int main() {
1
    int n;
2
    cin >> n;
3
    cout << findNthPrime(n) << endl;
4
    return 0;
5
}
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
150
863
863\n
Passed after ignoring Presentation Error
Test Case 2
200
1223
1223\n
Passed after ignoring Presentation Error










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.