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

















































































































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.