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

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

 

NPTEL » Programming in Modern C++

  Please scroll down for latest Programs. ðŸ‘‡ 



W1_Programming_Qs1

Due on 2025-08-07, 23:59 IST
Your last recorded submission was on 2025-07-30, 10:28 IST
Select the Language for this assignment. 
1
#include <iostream>
2
#include <string>
3
using namespace std;
4
5
int lenCompare(string s1, string s2){
6
7
    if (s1.length() < s2.length())   // LINE-1
8
        return -1;
9
10
    else if (s1.length() == s2.length()) // LINE-2
11
        return 0;
12
13
    else
14
        return 1;
15
}
0
int main(){
1
    string s1, s2;
2
    cin >> s1 >> s2;
3
    int res = lenCompare(s1, s2);
4
    if(res == 0)
5
        cout << "Equal length";
6
    else if(res == 1)
7
        cout << s1 << " is longer";
8
    else
9
        cout << s2 << " is longer";
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
hello worldwide
worldwide is longer
worldwide is longer
Passed
Test Case 2
sunshine darkness
Equal length
Equal length
Passed



W1_Programming_Qs2

Due on 2025-08-07, 23:59 IST
Your last recorded submission was on 2025-07-30, 10:29 IST
Select the Language for this assignment. 
1
#include <iostream>
2
#include <algorithm>
3
#include <string>
4
using namespace std;
5
6
bool compareChars(char a, char b) { // LINE-1
7
8
    return (a > b);             // LINE-2
9
}
0
int main(){
1
    string str;
2
    cin >> str;
3
    sort(str.begin(), str.end(), compareChars);
4
    cout << str;
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
delta
tleda
tleda
Passed
Test Case 2
apple
pplea
pplea
Passed



W1_Programming_Qs3

Due on 2025-08-07, 23:59 IST
Your last recorded submission was on 2025-07-30, 10:30 IST
Select the Language for this assignment. 
1
#include <iostream>
2
#include <algorithm>
3
using namespace std;
4
5
void replaceValue(int arr[], int n, int x, int y){
6
7
    replace(arr, arr + n, x, y);  // LINE-1
8
}
9
10
void reverseArray(int arr[], int n){
11
12
    reverse(arr, arr + n);  // LINE-2
13
}
0
int main(){
1
    int arr[] = {1, 4, 3, 4, 2, 4};
2
    int x, y;
3
    cin >> x >> y;
4
    int n = sizeof(arr)/sizeof(arr[0]);
5
    
6
    replaceValue(arr, n, x, y);
7
    for(int i = 0; i < n; i++)
8
        cout << arr[i] << " ";
9
    cout << endl;
10
    
11
    reverseArray(arr, n);
12
    for(int i = 0; i < n; i++)
13
        cout << arr[i] << " ";
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
4 9
1 9 3 9 2 9 \n
9 2 9 3 9 1
1 9 3 9 2 9 \n
9 2 9 3 9 1 
Passed after ignoring Presentation Error
Test Case 2
3 5
1 4 5 4 2 4 \n
4 2 4 5 4 1
1 4 5 4 2 4 \n
4 2 4 5 4 1 
Passed after ignoring Presentation Error




W2_Programming_Qs.1

Due on 2025-08-07, 23:59 IST
Your last recorded submission was on 2025-08-03, 19:01 IST
Select the Language for this assignment. 
1
#include <iostream>
2
using namespace std;
3
4
int process(const int& n){      //LINE-1
5
6
    return ( n * (n % 2 + 1));        //LINE-2
7
} 
0
int main(){
1
    int t;
2
    cin >> t;
3
    cout << process(t);
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
5
10
10
Passed
Test Case 2
6
6
6
Passed



W2_Programming_Qs.2

Due on 2025-08-07, 23:59 IST
Your last recorded submission was on 2025-08-03, 19:02 IST
Select the Language for this assignment. 
1
#include <iostream>
2
3
using namespace std;
4
5
#define AVG(X, Y) (((X) + (Y)) / 2)   // LINE-1
0
int main(){
1
    int a, b;
2
    cin >> a >> b;
3
    cout << AVG(a + 1, b + 1);
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
2 4
4
4
Passed
Test Case 2
3 -5
0
0
Passed



W2_Programming_Qs.3

Due on 2025-08-07, 23:59 IST
Your last recorded submission was on 2025-08-03, 19:03 IST
Select the Language for this assignment. 
1
#include <iostream>
2
using namespace std;
3
4
class Box{
5
    int value;
6
public:
7
    Box(int v): value(v) {}
8
9
    Box operator+ (const Box &b){     // LINE-1
10
11
        return Box(value + b.value);
12
    }
13
    void display(){ cout << value; }
14
};
0
int main(){
1
    int n1, n2;
2
    cin >> n1 >> n2;
3
    Box b1(n1), b2(n2);
4
    Box b3 = b1 + b2;
5
    b3.display();
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 10
15
15
Passed
Test Case 2
15 5
20
20
Passed




W6_Programming_Qs.1

Due on 2025-09-04, 23:59 IST
Your last recorded submission was on 2025-09-02, 11:19 IST
Select the Language for this assignment. 
1
#include <iostream>
2
#define PI 3.14
3
using namespace std;
4
5
class Shape{
6
    protected:
7
        double dim;
8
    public:
9
        Shape(double d) : dim(d) {}
10
        virtual double Volume();   //LINE-1
11
12
        void Print();   //LINE-2
13
};
0
double Shape::Volume(){ return dim*dim*dim; }
1
void Shape::Print(){ cout << Volume() << " "; }
2
3
class Sphere : public Shape{
4
    public:
5
        Sphere(double r) : Shape(r) {}
6
        double Volume(){ return (4.0/3)*PI*dim*dim*dim; }
7
};
8
9
int main(){
10
    double r;
11
    cin >> r;
12
    Shape s(r);
13
    Sphere sp(r);
14
    Shape *arr[2] = {&s,&sp};
15
    for(int i=0;i<2;i++)
16
        arr[i]->Print();
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
2
8 33.4933
8 33.4933 
Passed after ignoring Presentation Error
Test Case 2
1
1 4.18667
1 4.18667 
Passed after ignoring Presentation Error



W6_Programming_Qs.2

Due on 2025-09-04, 23:59 IST
Your last recorded submission was on 2025-09-02, 14:33 IST
Select the Language for this assignment. 
1
#include <iostream>
2
using namespace std;
3
4
class Alpha{
5
    int x;
6
    public:
7
        Alpha(int a) : x(a) {}
8
        virtual void display();                  //LINE-1
9
        friend void Add(Alpha &a1, Alpha &a2);   //LINE-2
10
};
11
12
class Beta : public Alpha{
13
    int y;
14
    public:
15
        Beta(int a, int b) : Alpha(a), y(b) {}
16
        void display(){
17
            Alpha::display();                    //LINE-3
18
            cout << y << " ";
19
        }
20
};
0
void Alpha::display(){ cout << x << " "; }
1
2
void Add(Alpha &a1, Alpha &a2){
3
    a1.x = a1.x + a2.x;
4
}
5
6
int main(){
7
    int m, n;
8
    cin >> m >> n;
9
    Alpha *p1 = new Beta(m,n);
10
    Alpha *p2 = new Alpha(n);
11
    Add(*p1, *p2);
12
    p1->display();
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
3 5
8 5
8 5 
Passed after ignoring Presentation Error
Test Case 2
2 4
6 4
6 4 
Passed after ignoring Presentation Error



W6_Programming_Qs.3

Due on 2025-09-04, 23:59 IST
Your last recorded submission was on 2025-09-02, 14:38 IST
Select the Language for this assignment. 
1
#include <iostream>
2
using namespace std;
3
4
class Base{
5
protected:
6
    int val;
7
public:
8
    Base(int v);
9
    virtual ~Base();   //LINE-1
10
    int getVal() { return val; }
11
};
12
13
class Derived : public Base{
14
public:
15
    Derived(int v);
16
    ~Derived();       //LINE-2
17
};
0
Base::Base(int v) : val(v) { cout << val << " "; }
1
Base::~Base(){ cout << val*2 << " "; }
2
Derived::Derived(int v) : Base(v) { cout << val*3 << " "; }
3
Derived::~Derived(){ cout << getVal() << " "; }
4
5
int main(){
6
    int n;
7
    cin >> n;  // Input value
8
    Derived *ptr = new Derived(n);
9
    Base *bptr = ptr;
10
    delete bptr;
11
    return 0;
12
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
5
5 15 5 10
5 15 5 10 
Passed after ignoring Presentation Error
Test Case 2
2
2 6 2 4
2 6 2 4 
Passed after ignoring Presentation Error





W7_Programming_Qs.1

Due on 2025-09-11, 23:59 IST
Your last recorded submission was on 2025-09-02, 14:48 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 *= 20; }
9
    };
10
    class IP2 {
11
        int i;
12
        public:
13
            IP2(int ai) : i(ai) {}
14
            int get() const { return i; }
15
16
            IP2(const IP1& p1) : i(p1.get()) {} //LINE-1
17
18
            operator IP1() const { return IP1(i); } //LINE-2
19
            void update() { i *= 10; }
20
    };
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
80:4:20:2
80:4:20:2
Passed
Test Case 2
5
140:7:50:5
140:7:50:5
Passed



W7_Programming_Qs.2

Due on 2025-09-11, 23:59 IST
Your last recorded submission was on 2025-09-02, 14:52 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
class A{
4
    int a = 5;
5
    public:
6
        void print(){
7
            cout << a << " ";
8
        }
9
};
10
class B{
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 A &t){
21
    int x;
22
    cin >> x;
23
    A &u = const_cast<A&>(t); //LINE-2
24
    u.print();
25
    B &v = reinterpret_cast<B&>(u); //LINE-3
26
    v = x;
27
    v.print();
28
}
0
int main(){
1
    A 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-09-11, 23:59 IST
Your last recorded submission was on 2025-09-02, 14:53 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
Himadri
Welcome Himadri
Welcome Himadri
Passed
Test Case 2
Soumen
Welcome Soumen
Welcome Soumen
Passed





W8_Programming_Qs.1

Due on 2025-09-18, 23:59 IST
Your last recorded submission was on 2025-09-17, 17:23 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[] = {'p', 'r', 'o', 'g', 'a', 'm'};
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
p, r, o, g, m,
30, 50, 40, \n
p, r, o, g, m, 
Passed after ignoring Presentation Error
Test Case 2
30 60 m s
30, 50, 60, 40, \n
p, r, o, m,
30, 50, 60, 40, \n
p, r, o, m, 
Passed after ignoring Presentation Error



W8_Programming_Qs.2

Due on 2025-09-18, 23:59 IST
Your last recorded submission was on 2025-09-17, 17:26 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";    //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 + 4) * 10);
10
        cVec.push_back(75 + 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
60, M\n
invalid\n
invalid
60, M\n
invalid\n
invalid\n
Passed after ignoring Presentation Error
Test Case 2
2 4 6
60, M\n
80, O\n
invalid
60, M\n
80, O\n
invalid\n
Passed after ignoring Presentation Error



W8_Programming_Qs.3

Due on 2025-09-18, 23:59 IST
Your last recorded submission was on 2025-09-17, 17:29 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 compare {
7
8
    bool operator()(const string& s1, const string& s2) const {    //LINE-1
9
10
        return s1.length() > s2.length() ;    //LINE-2
11
    }
12
};
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(), compare());
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
Chicken Ducks Dove Pig
Chicken Ducks Dove Pig 
Passed after ignoring Presentation Error
Test Case 2
5 grapes figs jackfruit apple blueberries
blueberries jackfruit grapes apple figs
blueberries jackfruit grapes apple figs 
Passed after ignoring Presentation Error





W9_Programming_Qs.1

Due on 2025-09-25, 23:59 IST
Your last recorded submission was on 2025-09-21, 08:12 IST
Select the Language for this assignment. 
1
#include <iostream>
2
#include <map>
3
4
std::map<int, int> findDigitFrequency(long long n){
5
    std::map<int, int> dFreq;
6
    while(n > 0)   //LINE-1
7
    {
8
        int digit = n % 10;
9
        dFreq[digit]++;    //LINE-2
10
        n = n / 10;
11
    }
12
    return dFreq;
13
}
14
15
void print(std::map<int, int> dFreq){
16
    for (auto it = dFreq.begin(); it != dFreq.end(); ++it)   //LINE-3
17
        std::cout << it->first << " -> " << it->second << std::endl;
18
}
0
int main(){
1
    long long num;
2
    std::cin >> num;
3
    std::map<int, int> dFreq = findDigitFrequency(num);
4
    print(dFreq);
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
120345
0 -> 1\n
1 -> 1\n
2 -> 1\n
3 -> 1\n
4 -> 1\n
5 -> 1
0 -> 1\n
1 -> 1\n
2 -> 1\n
3 -> 1\n
4 -> 1\n
5 -> 1\n
Passed after ignoring Presentation Error
Test Case 2
100220
0 -> 3\n
1 -> 1\n
2 -> 2
0 -> 3\n
1 -> 1\n
2 -> 2\n
Passed after ignoring Presentation Error



W9_Programming_Qs.2

Due on 2025-09-25, 23:59 IST
Your last recorded submission was on 2025-09-21, 08:14 IST
Select the Language for this assignment. 
1
#include<iostream>
2
#include<list>
3
#include<algorithm>
4
5
template<typename T>
6
struct greaterThanOrEqual {
7
    T threshold_;
8
    greaterThanOrEqual(T threshold = 0) : threshold_(threshold) { }
9
    bool operator()(T x) { return x >= threshold_; }
10
};
11
template<typename T>                                             // LINE-1
12
void printFromThreshold(std::list<T>& li, T threshold) {
13
    greaterThanOrEqual<T> pred(threshold);
14
    auto it = li.begin();
15
    while( (it = std::find_if(it, li.end(), pred)) != li.end() ) {  // LINE-2
16
        std::cout << *it << " ";
17
        it++;                                                    // LINE-3
18
    }
19
}
0
int main(){
1
    std::list<int> li {30, 70, 10, 40, 20, 50, 60, 80};
2
    int threshold;
3
    std::cin >> threshold;
4
    printFromThreshold(li, threshold);
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
40
70 40 50 60 80
70 40 50 60 80 
Passed after ignoring Presentation Error
Test Case 2
55
70 60 80
70 60 80 
Passed after ignoring Presentation Error



W9_Programming_Qs.3

Due on 2025-09-25, 23:59 IST
Your last recorded submission was on 2025-09-21, 08:16 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 Student{
8
    private:
9
        string name;
10
        int marks;
11
    public:
12
        Student(string _name, int _marks) : name(_name), marks(_marks){}
13
        string getName() const{
14
            return name;
15
        }
16
        int getMarks() const{
17
            return marks;
18
        }
19
        friend ostream& operator<<(ostream& os, const Student& s);
20
};
21
22
ostream& operator<<(ostream& os, const Student& s){
23
    os << s.name << '-' << s.marks << endl;
24
    return os;
25
}
26
struct compareByMarksDesc{
27
28
    bool operator()(const Student& a, const Student& b) const {
29
        return a.getMarks() > b.getMarks();
30
    }
31
32
};
33
34
struct compareByNameAsc{
35
36
    bool operator()(const Student& a, const Student& b) const {
37
        return a.getName() < b.getName();
38
    }
39
40
};
0
int main() {
1
    int n;              //number of students
2
    cin >> n;
3
    vector<Student> students;
4
    for(int i = 0; i < n; i++){
5
        string na;
6
        int ma;
7
        cin >> na >> ma;    //student's name and marks
8
        Student s(na, ma);
9
        students.push_back(s);
10
    }
11
    int t;              //sort option
12
    cin >> t;
13
    if(t == 1)
14
        sort(students.begin(), students.end(), compareByMarksDesc());
15
    else if(t == 2)
16
        sort(students.begin(), students.end(), compareByNameAsc());
17
    for(vector<Student>::iterator p = students.begin(); p != students.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
arjun 78
meera 95
kiran 88
sita 72
1
meera-95\n
kiran-88\n
arjun-78\n
sita-72
meera-95\n
kiran-88\n
arjun-78\n
sita-72\n
Passed after ignoring Presentation Error
Test Case 2
5
raju 60
geeta 85
suresh 75
anita 80
bala 70
2
anita-80\n
bala-70\n
geeta-85\n
raju-60\n
suresh-75
anita-80\n
bala-70\n
geeta-85\n
raju-60\n
suresh-75\n
Passed after ignoring Presentation Error





W10_Programming_Qs.1

Due on 2025-10-02, 23:59 IST
Your last recorded submission was on 2025-09-26, 07:24 IST
Select the Language for this assignment. 
1
#include <iostream>
2
#include <string>
3
#include <algorithm>
4
5
int action(int x){
6
    return x * 2;
7
}
8
9
std::string action(const std::string& s){
10
    std::string rev = s;
11
    std::reverse(rev.begin(), rev.end());
12
    return rev;
13
}
14
template <class T>
15
auto transform(const T& val) {     // LINE-1
16
17
    return action(val);     // LINE-2
18
}
0
int main(){
1
    int a;
2
    std::string b;
3
    std::cin >> a >> b;
4
    std::cout << transform(a) << " ";
5
    std::cout << transform(b);
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
7 code
14 edoc
14 edoc
Passed
Test Case 2
5 hello
10 olleh
10 olleh
Passed



W10_Programming_Qs.2

Due on 2025-10-02, 23:59 IST
Your last recorded submission was on 2025-09-26, 07:26 IST
Select the Language for this assignment. 
1
#include <iostream>
2
3
class IntWrap { 
4
    public: 
5
        IntWrap() : ip_(nullptr) { }
6
        IntWrap(int x) : ip_(new int(x)) { }
7
        IntWrap(const IntWrap& ob) : ip_(new int(*ob.ip_)) {}  // LINE-1: copy constructor 
8
        IntWrap& operator=(const IntWrap& ob) {            // LINE-2: copy assignment 
9
            if (this != &ob) {
10
                delete ip_;
11
                ip_ = new int(*(ob.ip_) + 10);
12
            }
13
            return *this;
14
        }
15
        IntWrap(IntWrap&& ob) noexcept : ip_(ob.ip_) {         // LINE-3: move constructor 
16
            ob.ip_ = nullptr;
17
        }
18
        IntWrap& operator=(IntWrap&& ob) noexcept {               // LINE-4: move assignment 
19
            if (this != &ob) {
20
                ip_ = ob.ip_;
21
                ob.ip_ = nullptr;
22
            }
23
            return *this;
24
        }
0
void print(){
1
            if(ip_ == nullptr)
2
                std::cout << "moved, ";
3
            else
4
                std::cout << *ip_ << ", ";
5
        }
6
        ~IntWrap(){ delete ip_; }
7
    private:
8
        int* ip_ = nullptr;
9
};
10
11
int main(){
12
    int n;
13
    std::cin >> n;
14
    IntWrap w1(n); 
15
    IntWrap w2 = w1;   
16
    IntWrap w3(0);     
17
    w3 = w1;           
18
    w1.print(); w2.print(); w3.print();
19
    IntWrap w4 = std::move(w1);
20
    IntWrap w5; w5 = std::move(w1);
21
    w1.print(); w4.print(); w5.print();
22
    return 0;
23
}
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, 5, 15, moved, 5, moved,
5, 5, 15, moved, 5, moved, 
Passed after ignoring Presentation Error
Test Case 2
20
20, 20, 30, moved, 20, moved,
20, 20, 30, moved, 20, moved, 
Passed after ignoring Presentation Error



W10_Programming_Qs.3

Due on 2025-10-02, 23:59 IST
Your last recorded submission was on 2025-09-26, 07:27 IST
Select the Language for this assignment. 
1
#include <iostream>
2
class Matrix {
3
    public:
4
        explicit Matrix(int v = 0) : val(v) {}
5
        Matrix operator*(int n) {
6
            return Matrix(val * n);
7
        }
8
        Matrix operator*(Matrix m) {
9
            return Matrix(val * m.val);
10
        }
11
        friend std::ostream& operator<<(std::ostream& os, const Matrix& m);
12
    private:
13
        int val;
14
};
15
std::ostream& operator<<(std::ostream& os, const Matrix& m){
16
    os << m.val;
17
    return os;
18
}
19
template <class T1, class T2>            // LINE-1
20
void multiply(T1 n1, T2 n2) {          // LINE-2
21
    using Tmp = decltype(n1 * n2);       // LINE-3: define new type Tmp
22
    Tmp prod = n1 * n2;
23
    std::cout << prod << std::endl;
24
}
0
int main(){
1
    int a, b, x, y;
2
    std::cin >> a >> b >> x >> y;
3
    Matrix m1(x);
4
    Matrix m2(y);
5
    multiply(m1, a);
6
    multiply(m1, m2);
7
    multiply(a, 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
2 3 4 5
8\n
20\n
6
8\n
20\n
6\n
Passed after ignoring Presentation Error
Test Case 2
-1 10 -6 2
6\n
-12\n
-10
6\n
-12\n
-10\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.