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

 Programming In Modern C++


Subscribe to our YouTube Channel :  Swayam Solver

  Please scroll down for latest Programs. 👇 




W1_Programming_Qs.1

Due on 2023-08-10, 23:59 IST



Consider the following program. Fill in the blanks as per the instructions given below:
    • at LINE-1 with stack declaration,
    • at LINE-2 to push values into stack,
    • at LINE-3 with appropriate statement
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-07-23, 18:53 IST
Select the Language for this assignment. 
1
#include<iostream>
2
#include<cstring>
3
#include<stack>
4
using namespace std;
5
6
7
int main() {
8
    char str[20];
9
    char ch;
10
    cin >> str;
11
stack<char>s ; //LINE-1
12
13
    for(int i = 0; i < strlen(str); i+=2)
14
        s.push(str[i]); //LINE-2
15
16
    int len = s.size();
17
18
    for(int i = 0; i < len; i++) {
19
20
        ch = s.top();  //LINE-3
0
cout << ch;
1
2
        s.pop();
3
    }
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
computer
eumc
eumc
Passed
Test Case 2
programming
gimrop
gimrop
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed



W1_Programming_Qs.2

Due on 2023-08-10, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below.
    • at LINE-1 with appropriate header statement,
    • at LINE-2 with appropriate statement to calculate Euclidean distance
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-07-23, 19:07 IST
Select the Language for this assignment. 
1
#include <iostream>
2
#include <cmath>     //LINE-1 
3
4
using namespace std;
5
6
struct point{
7
    int x, y;
8
};
9
10
double get_len(point p1, point p2){
11
    return sqrt((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y)) ;    //LINE-2
12
}
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 << round(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
4 3 6 9
6
6
Passed
Test Case 2
2 5 3 9
4
4
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed


W1_Programming_Qs.3

Due on 2023-08-10, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
   • at LINE-1 with appropriate function header,
   • at LINE-2 with appropriate return statement
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-07-23, 19:08 IST
Select the Language for this assignment. 
1
#include <iostream>
2
#include <algorithm>
3
using namespace std;
4
5
6
7
bool max_str(string c1, string c2) {    //LINE-1
8
9
    return c1 > c2;            //LINE-2
10
}
0
int main() {
1
    std::string words[3], word;
2
    for(int i = 0; i < 3; i++){
3
        cin >> word;
4
        words[i] = word;
5
    }
6
    sort(words, words + 3, max_str);
7
    for (int i = 0; i < 3; 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
hello hi bye
hi hello bye
hi hello bye 
Passed after ignoring Presentation Error
Test Case 2
soumen arup himadri
soumen himadri arup
soumen himadri arup 
Passed after ignoring Presentation Error





Private Test cases used for EvaluationStatus
Test Case 1
Passed


 

W2_Programming_Qs.1

Due on 2023-08-10, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
   • at LINE-1 with function header
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-07-30, 13:23 IST
Select the Language for this assignment. 
1
#include <iostream>
2
using namespace std;
3
4
void print(int a, int b=0) { // LINE-1
5
6
    int r = b + a;
7
8
    cout << r;
9
}
0
int main() {
1
2
    int a, b;
3
4
    cin >> a >> b;
5
6
    if (b < 0)
7
        print(a);
8
    else
9
        print(a,b);
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
2 3
5
5
Passed
Test Case 2
8 -2
8
8
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed



W2_Programming_Qs.2

Due on 2023-08-10, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below.
   • at LINE-1 with appropriate function parameter,
   • at LINE-2 with appropriate statement
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-07-30, 13:24 IST
Select the Language for this assignment. 
1
#include <iostream>
2
using namespace std;
3
4
int Fun(int& x) { // LINE-1
5
6
    x = x*x; // LINE-2
7
8
    return x;
9
}
0
int main() {
1
    int x, y;
2
    cin >> x;
3
    y = Fun(x);
4
    cout << x << " " << y;
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
4
16 16
16 16
Passed
Test Case 2
2
4 4
4 4
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed


W2_Programming_Qs.3

Due on 2023-08-10, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
   • at LINE-1 with appropriate function header,
   • at LINE-2 with appropriate return statement
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-07-30, 13:24 IST
Select the Language for this assignment. 
1
#include <iostream>
2
using namespace std;
3
struct point {
4
    int x, y;
5
};
6
point operator+ ( point& pt1, point& pt2) { //LINE-1
7
8
    pt1.x += pt2.x;
9
    pt1.y += pt2.y;
10
11
    return pt1;    //LINE-2
12
}
0
int main() {
1
    int a, b, c, d;
2
    cin >> a >> b >> c >> d;
3
    point p1 = {a, b};
4
    point p2 = {c, d};
5
    point np = p1 + p2;
6
    cout << "(" << p1.x << ", " << p1.y << ")" << "(" << 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
1 2 3 4
(4, 6)(4, 6)
(4, 6)(4, 6)
Passed
Test Case 2
2 4 6 8
(8, 12)(8, 12)
(8, 12)(8, 12)
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed



W3_Programming_Qs.1

Due on 2023-08-17, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
    • Complete two constructor statements at LINE-1 and LINE-2,
    • Complete the return statement at LINE-3 to calculate the manhattan distance between two points,
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-08-08, 22:30 IST
Select the Language for this assignment. 
1
#include<iostream>
2
#include<cmath>
3
using namespace std;
4
5
class Point{
6
    const int x,y;
7
8
public:
9
    Point(int _x=0, int _y=0) : x(_x), y(_y) {} //LINE-1
10
11
    Point(const Point& p) : x(p.x), y(p.y) {} //LINE-2
12
13
    double distance(Point p){
14
15
        return abs((p.x-x)) + abs((p.y - y)) ; //LINE-3
16
    }
0
void print(){ cout << "(" << x << "," << y << ")" << endl; }
1
2
};
3
4
int main(){
5
    int x1,x2,y1,y2;
6
    cin >> x1 >> y1 >> x2 >> y2;
7
8
    Point p1(x1,y1), p2(x2,y2);
9
    p1.print();
10
11
    p2.print();
12
    cout << "Distance: " << p1.distance(p2);
13
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
1 2 3 4
(1,2)\n
(3,4)\n
Distance: 4
(1,2)\n
(3,4)\n
Distance: 4
Passed
Test Case 2
1 -1 2 -2
(1,-1)\n
(2,-2)\n
Distance: 2
(1,-1)\n
(2,-2)\n
Distance: 2
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed


W3_Programming_Qs.2

Due on 2023-08-17, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below.
    • at LINE-1 with constructor definition,
    • at LINE-2 with appropriate statement to deallocate array memory
such that it will satisfy the given test cases. 
Your last recorded submission was on 2023-08-08, 22:31 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
4
class Array{
5
    int *arr;
6
    int size;
7
8
public:
9
    Array(int n) : size(n) { arr = new int[n]; } //LINE-1
10
11
    ~Array(){ delete arr; } //LINE-2
0
void Enter(){
1
        for(int i=0;i<size;i++)
2
            cin >> arr[i];
3
    }
4
    void FindMin(){
5
        int min = 999;
6
        for(int i=0;i<size;i++){
7
            if(min > arr[i])
8
                min = arr[i];
9
        }
10
        cout << "Min: " << min;
11
    }
12
};
13
int main(){
14
    int n;
15
    cin >> n;
16
    Array a(n);
17
    a.Enter();
18
    a.FindMin();
19
    return 0;
20
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
4
1 3 5 8
Min: 1
Min: 1
Passed
Test Case 2
3
7 3 9
Min: 3
Min: 3
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed


W3_Programming_Qs.3

Due on 2023-08-17, 23:59 IST
Consider the following program. Fill in the blanks at LINE-1, LINE-2 and LINE-3 with
Consider the following program. Fill in the blanks at LINE-1, LINE-2 and LINE-3 with
appropriate keywords such that it will satisfy the given test cases.
Your last recorded submission was on 2023-08-08, 22:31 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
class Student{
4
    const int sid;
5
    string sname;
6
7
    mutable int marks; //LINE-1
8
9
    public:
10
        Student(int a, string b, int c) : sid(a), sname(b), marks(c) {}
11
12
        void updateMarks(int x) const { marks += x; } //LINE-2
13
14
        void print() const {    //LINE-3
0
cout << sid << " : " << sname << " : " << marks; 
1
        } 
2
};
3
4
int main(){
5
    string n;
6
    int i, m, u;
7
    cin >> i >> n >> m >> u;
8
    const Student s1(i, n, m);
9
    s1.updateMarks(u);
10
    s1.print();
11
    return 0;
12
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
1 Raj 36 5
1 : Raj : 41
1 : Raj : 41
Passed
Test Case 2
2 Amal 48 20
2 : Amal : 68
2 : Amal : 68
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed



W4_Programming_Qs.1

Due on 2023-08-24, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
    • Complete the variable declaration at LINE-1,
    • Complete the function prototype at LINE-2 and LINE-3 with appropriate keywords
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-08-12, 22:41 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
class Employee{
4
    const int id;
5
    string name;
6
    mutable int salary; //LINE-1
7
8
    public:
9
        Employee(int a, string b, int c) : id(a), name(b), salary(c) {}
10
11
        void updateSal(int x) const{ salary += x; } //LINE-2
12
13
        void print() const{ cout << id << " : " << name << " : " << salary; } //LINE-3
14
};
0
int main(){
1
    string n;
2
    int i, m, u;
3
    cin >> i >> n >> m >> u;
4
    const Employee e1(i, n, m);
5
    e1.updateSal(u);
6
    e1.print();
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 Raj 10000 1000
1 : Raj : 11000
1 : Raj : 11000
Passed
Test Case 2
2 Zakir 50000 5000
2 : Zakir : 55000
2 : Zakir : 55000
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed


W4_Programming_Qs.2

Due on 2023-08-24, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below.
    • at LINE-1 with appropriate forward declaration,
    • at LINE-2 with appropriate statement
such that it will satisfy the given test cases
Your last recorded submission was on 2023-08-12, 22:42 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
4
class B; //LINE-1
5
class A{
6
    int a_ = 0;
7
    public:
8
        A(int x) : a_(x) {}
9
        int mulB (B&);
10
        int subtractB (B&);
11
};
12
class B{
13
    int b_;
14
    public:
15
        B(int y) : b_(y) {  }
16
17
        friend class A; //LINE-2
18
};
0
int A::mulB(B &b) {
1
    return (a_ * b.b_);
2
}
3
int A::subtractB(B &b) {
4
    return (a_ - b.b_);
5
}
6
int main(){
7
    int x, y;
8
    cin >> x >> y;
9
    A t1(x);
10
    B t2(y);
11
    cout << t1.mulB(t2) << " " << t1.subtractB(t2);
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
3 4
12 -1
12 -1
Passed
Test Case 2
2 7
14 -5
14 -5
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed


W4_Programming_Qs.3

Due on 2023-08-24, 23:59 IST
Consider the following program. Fill in the blanks at LINE-1, LINE-2 and LINE-3 with appropriate statements such that it will satisfy the given test cases. 
Your last recorded submission was on 2023-08-12, 22:43 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
class Singleton{
4
    int data;
5
    static Singleton *ins;                  //LINE-1
6
    Singleton(int i) : data(i) {}
7
    public:
8
        int get(){ return data; }
9
        static Singleton* createIns(int i){      //LINE-2
10
            if(!ins)
11
                ins = new Singleton(i);    //LINE-3
12
            return ins;
13
        }
14
        ~Singleton(){ cout << data; }
15
};
0
Singleton *Singleton::ins = 0;
1
void fun(int x){
2
    Singleton *s = Singleton::createIns(x+5);
3
    cout << s->get();
4
}
5
int main(){
6
    int i, j;
7
    cin >> i >> j;
8
    Singleton *s = Singleton::createIns(i);
9
    cout << s->get();
10
    fun(j);
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
1 2
11
11
Passed
Test Case 2
2 3
22
22
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed



W5_Programming_Qs.1

Due on 2023-08-31, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
   • Complete the inheritance statement at LINE-1,
   • Complete the return statement at LINE-2 and LINE-3 to calculate the volume and surface
     area of a cube,
such that it will satisfy the given test cases. 
Your last recorded submission was on 2023-08-22, 14:30 IST
Select the Language for this assignment. 
1
#include <iostream>
2
using namespace std;
3
class Volume {
4
    public:
5
        double getValue(int a) { return (a * a * a); }
6
};
7
class SurfaceArea {
8
    public:
9
        double getValue(int a) { return 6 * a * a; }
10
};
11
class Cube : public Volume, public SurfaceArea { //LINE-1
12
    int _a;
13
14
    public:
15
        Cube(int a) : _a(a) { }
16
17
        double getVolume() { return Volume::getValue(_a); } //LINE-2
18
19
        double getSurfaceArea() { return SurfaceArea::getValue(_a) ; } //LINE-3
20
};
0
int main() {
1
    int a;
2
    cin >> a;
3
    Cube c(a);
4
    cout << c.getVolume() << ", " << c.getSurfaceArea();
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
4
64, 96
64, 96
Passed
Test Case 2
3
27, 54
27, 54
Passed


W5_Programming_Qs.2

Due on 2023-08-31, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below.
   • at LINE-1 with appropriate keyword,
   • at LINE-2 and LINE-3 with appropriate constructor statements
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-08-22, 14:31 IST
Select the Language for this assignment. 
1
#include <iostream>
2
using namespace std;
3
class Vehicle{
4
    string vehicleName;
5
    int noOfWheels;
6
    protected:
7
        Vehicle(string s, int w) : vehicleName(s), noOfWheels(w) { }
8
    public:
9
        friend void vehicleDetails(const Vehicle&); //LINE-1
10
};
11
class Twowheeler : public Vehicle{
12
    public:
13
        Twowheeler(string n) : Vehicle(n,2) { } //LINE-2
14
};
15
class Fourwheeler : public Vehicle{
16
    public:
17
        Fourwheeler(string n) : Vehicle(n,4) { } //Line-3
18
};
0
void vehicleDetails(const Vehicle &v){
1
    cout << v.vehicleName << ": ";
2
    if(v.noOfWheels == 2)
3
        cout << "Two Wheeler";
4
    else if(v.noOfWheels == 4)
5
        cout << "Four Wheeler";
6
}
7
int main(){
8
    string s;
9
    int n;
10
    Vehicle *v;
11
    cin >> s >> n;
12
    if(n==2)
13
        v = new Twowheeler(s);
14
    else if(n==4)
15
        v = new Fourwheeler(s);
16
    vehicleDetails(*v);
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
Bus 4
Bus: Four Wheeler
Bus: Four Wheeler
Passed
Test Case 2
Bike 2
Bike: Two Wheeler
Bike: Two Wheeler
Passed



W5_Programming_Qs.3

Due on 2023-08-31, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below.
    • at LINE-1 with appropriate inheritance statement,
    • at LINE-2 with appropriate constructor statement
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-08-22, 14:26 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
17
    int d;
18
19
public:
20
21
    D(int x) : d(x), B1(x+5), B2(x+10) {} //LINE-2
0
void show(){
1
        cout << d << ", " << b1 << ", " << b2;
2
    }
3
};
4
int main(){
5
    int x;
6
    cin >> x;
7
    D t1(x);
8
    t1.show();
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
1
1, 6, 11
1, 6, 11
Passed
Test Case 2
5
5, 10, 15
5, 10, 15
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed



W6_Programming_Qs.1

Due on 2023-09-07, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
   • Complete the destructor statement,
   • Complete the constructor statement,
such that it will satisfy the given test cases
Your last recorded submission was on 2023-08-27, 10:38 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
class B{
4
public:
5
    B(){ cout << "1 "; }
6
    B(double n){ cout << n << " "; }
7
8
    virtual ~B(); //LINE-1
9
};
10
11
class D : public B{
12
public:
13
14
    D(double n) : B(n)     //LINE-2
0
{ cout << n * 3 << " "; } 
1
    D(){ cout << "3 "; }
2
    virtual ~D(){ cout << "4 "; }
3
};
4
B::~B(){ cout << "2"; }
5
int main(){
6
    int i;
7
    cin >> i;
8
    B *pt = new D(i);
9
    delete pt;
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
4 12 4 2
4 12 4 2
Passed
Test Case 2
2
2 6 4 2
2 6 4 2
Passed


W6_Programming_Qs.2

Due on 2023-09-07, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below.
   • at LINE-1, define fun as pure abstract function,
   • at LINE-2, complete constructor definition,
   • at LINE-3, complete constructor definition,
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-08-27, 10:39 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
class Test{
4
public:
5
    virtual void fun()=0; //Line-1 
6
};
7
class ReTest1 : public Test{
8
    int d1;
9
public:
10
    ReTest1(int n) : d1(n*2){ } //Line-2
11
    void fun();
12
};
13
class ReTest2 : public Test{
14
    int d2;
15
public:
16
    ReTest2(int n) : d2(n*3){ } //Line-3
17
    void fun(){
18
        cout << d2;    // copy this line also
19
    }
20
};
0
void ReTest1::fun(){
1
    cout << d1 << " ";
2
}
3
int main(){
4
    int i;
5
    cin>>i;
6
    Test *t1 = new ReTest1(i);
7
    Test *t2 = new ReTest2(i);
8
    t1->fun();
9
    t2->fun();
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
2
4 6
4 6
Passed
Test Case 2
3
6 9
6 9
Passed



W6_Programming_Qs.3

Due on 2023-09-07, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below.
   • at LINE-1, declare the function show() as pure virtual function,
   • at LINE-2, with appropriate function call,
   • at LINE-3, with appropriate function header,
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-08-27, 10:40 IST
Select the Language for this assignment. 
1
#include <iostream>
2
using namespace std;
3
class shape{
4
protected:
5
    int a,b;
6
    shape(int x, int y) : a(x), b(y) {}
7
public:
8
    virtual void show()=0;    //LINE-1
9
};
10
class triangle : public shape{
11
public:
12
    triangle(int x, int y) : shape(x,y){}
13
    void Area();
14
    void sum();     //Add this line 
15
    void show(){
16
        sum(); //LINE-2
17
        Area();
18
    }
19
};
20
void triangle::sum(){ //LINE-3
21
    cout << a+b << " ";
22
}
0
void triangle::Area(){ cout << (0.5 * a * b); }
1
int main(){
2
    int a, b;
3
    cin >> a >> b;
4
    shape *sp = new triangle(a, b);
5
    sp->show();
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
10 15
25 75
25 75
Passed
Test Case 2
5 10
15 25
15 25
Passed



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


W7_Programming_Qs.1

Due on 2023-09-14, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
   • at LINE-1, complete the constructor statement,
   • at LINE-2 and LINE-3, complete the operator overloading function header,
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-09-04, 11:11 IST
Select the Language for this assignment. 
1
#include<iostream>
2
#include<cctype>
3
using namespace std;
4
class Char{
5
    char ch;
6
    public:
7
         Char(char _ch) : ch(tolower(_ch)){} //LINE-1
8
9
        operator char(){ return ch; } //LINE-2
10
11
         operator int(){ return ch - 'a' + 1; } //LINE-3
12
};
0
int main(){
1
    char c;
2
    cin >> c;
3
    Char cb = c;
4
    cout << (char)cb << ": position is " << int(cb);
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
C
c: position is 3
c: position is 3
Passed
Test Case 2
G
g: position is 7
g: position is 7
Passed


W7_Programming_Qs.2

Due on 2023-09-14, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below.
  • at LINE-1, complete the constructor definition,
  • at LINE-2, complete the overload function header,
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-09-04, 11:16 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, "Coding is ");
12
            strcat(t_str, _str);
13
            return t_str;
14
        }
15
};
0
int main(){
1
    char s[20];
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
fun
Coding is fun
Coding is fun
Passed
Test Case 2
easy
Coding is easy
Coding is easy
Passed


W7_Programming_Qs.3

Due on 2023-09-14, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
  • at LINE-1, complete the overload function header,
  • at LINE-2, complete the casting operator statement,
  • at LINE-3, complete the casting operator statement,
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-09-04, 11:15 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
class ClassA{
4
    int a = 10;
5
    public:
6
        void display(){
7
            cout << a << " ";
8
        }
9
};
10
class ClassB{
11
    int b = 20;
12
    public:
13
        void display(){
14
            cout << b;
15
        }
16
        void operator= (int x){ //LINE-1
17
            b = b + x;
18
        }
19
};
20
21
22
void fun(const ClassA &t, int x){
23
    ClassA &u =  const_cast<ClassA&>(t); //LINE-2
24
    u.display();
25
    ClassB &v = reinterpret_cast<ClassB&>(u); //LINE-3
26
    v = x;
27
    v.display();
28
}
0
int main(){
1
    ClassA t1;
2
    int a;
3
    cin >> a;
4
    fun(t1,a);
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
10 15
10 15
Passed
Test Case 2
3
10 13
10 13
Passed


W8_Programming_Qs.1

Due on 2023-09-21, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
    • Fill in the blank at LINE-1 and LINE-2 with appropriate statements for class template specialization.
    • Fill in the blank at LINE-3 with appropriate initializer list.
The program must satisfy the given test cases.
Your last recorded submission was on 2023-09-11, 10:13 IST
Select the Language for this assignment. 
1
#include<iostream>
2
#include<cstring>
3
#include<cstdlib>
4
5
template<typename T>
6
class Manipulator{
7
    T val;
8
    public:
9
        Manipulator(T _val = 0) : val(_val) { }
10
        T deduct(int d){
11
            T t = val - d;
12
            return t;
13
        }
14
};
15
template<>    //LINE-1
16
17
class Manipulator<const char*>  {   //LINE-2   
18
 
19
    char* val;
20
    public:
21
        Manipulator(const char* _val = 0) : val(strdup(_val)) { }    //LINE-3
22
        char* deduct(int d){
23
            char* buf = (char*)malloc(strlen(val) - d + 1);
24
            int i;
25
            for(i = 0; i < strlen(val) - d; i++)
26
                buf[i] = val[i];
27
            buf[i] = '\0';
28
            return buf;    
29
        }
30
};
0
int main(){
1
    int a;
2
    std::cin >> a;;
3
    Manipulator<float> f = 100.45;
4
    Manipulator<const char*> s("programming");
5
    std::cout << f.deduct(a) << ", ";
6
    std::cout << s.deduct(a);
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
3
97.45, programm
97.45, programm
Passed
Test Case 2
5
95.45, progra
95.45, progra
Passed


W8_Programming_Qs.2

Due on 2023-09-21, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below.
    • Fill in the blank at LINE-1 with appropriate template declaration for class DataSet.
    • Fill in the blank at LINE-2 with appropriate declaration of array arr.
    • Fill in the blank at LINE-3 with appropriate parameter / parameters for function operator=.
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-09-11, 10:14 IST
Select the Language for this assignment. 
1
#include <iostream>
2
3
template<class T, int N>     // LINE-1
4
class DataSet {
5
    private:
6
        T arr[N];            // LINE-2
7
        int i;
8
    public:
9
        DataSet() : i(-1) { }
10
        void operator=(T data){ // LINE-3
11
            arr[++i] = data;
12
        }
0
void print() {
1
            for (int j = N - 1; j >= 0; j--)
2
                std::cout << arr[j] << " ";
3
        }
4
};
5
int main() {
6
    const int n = 3;
7
    DataSet<char, n> ds1;
8
    for (int i = 0; i < n; i++) {
9
        char j;
10
        std::cin >> j;
11
        ds1 = j;
12
    }
13
    DataSet<int, n> ds2;
14
    for (int i = 0; i < n; i++) {
15
        int j;
16
        std::cin >> j;
17
        ds2 = j;
18
    }
19
    ds1.print();
20
    ds2.print();
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
a b c
1 2 3
c b a 3 2 1
c b a 3 2 1 
Passed after ignoring Presentation Error
Test Case 2
x y z
10 20 30
z y x 30 20 10
z y x 30 20 10 
Passed after ignoring Presentation Error


W8_Programming_Qs.3

Due on 2023-09-21, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
   • Fill in the blank at LINE-1 with appropriate constructor for structure Stat.
   • Fill in the blank at LINE-2 with appropriate header declaration for functor.
   • Fill in the blank at LINE-3 with appropriate return statement.
The program must satisfy the given test cases.
Your last recorded submission was on 2023-09-11, 10:14 IST
Select the Language for this assignment. 
1
#include <iostream>
2
3
struct Stat {
4
    int s;
5
    Stat(int _s) :  s(_s){}  //LINE-1  
6
    
7
    double operator() (int arr[], int n) {    //LINE-2   
8
 
9
        for(int i = 0; i < n; i++)
10
            s += arr[i];
11
        double a = (double)s / n;
12
13
        return a;                //LINE-3
14
    }
15
};
0
int main(){
1
    int a, b, c[10];
2
    std::cin >> a;
3
    for(int i = 0; i < a; i++){
4
        std::cin >> b;
5
        c[i] = b;
6
    }
7
    int sum = 0;
8
    Stat st(sum);
9
    double avg = st(c, a);
10
    std::cout << st.s << " " << avg;
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
4 10 20 30 40
100 25
100 25
Passed
Test Case 2
6 1 2 3 4 5 6
21 3.5
21 3.5
Passed



W9_Programming_Qs.1

Due on 2023-09-28, 23:59 IST
Consider the following program that finds the minimum element in an array. Fill in the blanks
as per the instructions given below:
   • Fill in the blank at LINE-1 with appropriate template declaration.
   • Fill in the blanks at LINE-2 and LINE-3 with appropriate conditional statement.
The program must satisfy the given test cases.
Your last recorded submission was on 2023-09-18, 17:05 IST
Select the Language for this assignment. 
1
#include<iostream>
2
3
template<class T, class Itr>    //LINE-1
4
void min(Itr first, Itr last, T& mv) {
5
    mv = *first++;
6
    while (first !=last) {          //LINE-2
7
8
        if(*first<mv)            //LINE-3
9
            mv = *first;
10
        ++first;
11
    }
12
}
0
int main(){
1
    int iArr[10];
2
    int n;
3
    std::cin >> n;
4
    for(int i = 0; i < n; i++)
5
        std::cin >> iArr[i];
6
        
7
    double minVal = 0.0;
8
    min(iArr, iArr + n, minVal);
9
    std::cout << minVal;
10
    return 0;
11
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
5
50 27 10 70 23
10
10
Passed
Test Case 2
6
94 5 22 45 32 1
1
1
Passed



W9_Programming_Qs.2

Due on 2023-09-28, 23:59 IST
Consider the following program that takes inputs a lower limit (l) and an upper limit (u) of
a vector. If all the elements of the input vector are within the given lower and upper limits,
the program prints "all in [l, u]". Otherwise, the program prints the first element of the vector
which is not within the given limits. Fill in the blanks as per the instructions given below:
  • at LINE-1 with appropriate header to overload function operator,
  • at LINE-2 with appropriate template definition,
  • at LINE-3 with appropriate condition,
such that the program will satisfy the given test cases. 
Your last recorded submission was on 2023-09-18, 17:06 IST
Select the Language for this assignment. 
1
#include<iostream>
2
#include<vector>
3
4
struct Bound{
5
    Bound(int l, int u) : l_(l), u_(u){}
6
7
    bool operator()(int n){     //LINE-1
8
        return (n >= l_ && n <= u_);
9
    }
10
    int l_, u_;
11
};
12
13
template<class Itr, class Pred>      //LINE-2
14
15
Itr search(Itr first, Itr last, Pred bd) {
16
    while (first != last){
17
18
        if(!bd(*first))     //LINE-3
19
            return first;
20
        ++first;
21
    }     
22
    return first;
23
}
0
int main(){
1
    int iArr[] = { 70, 20, 50, 40, 90, 10, 80 }; 
2
    std::vector<int> iVec(iArr, iArr + sizeof(iArr) / sizeof(*iArr));
3
    int l, u;
4
    std::cin >> l >> u;
5
    Bound bd(l, u);
6
    
7
    std::vector<int>::iterator it = search(iVec.begin(), iVec.end(), bd);
8
    
9
    if(it == iVec.end())
10
        std::cout << "all in [" << l << ", " << u << "]";
11
    else
12
        std::cout << *it << " is the first element not in [" << l << ", " << u << "]";
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 100
all in [10, 100]
all in [10, 100]
Passed
Test Case 2
10 70
90 is the first element not in [10, 70]
90 is the first element not in [10, 70]
Passed


W9_Programming_Qs.3

Due on 2023-09-28, 23:59 IST
Consider the following program, which computes the frequency of occurrence (histogram) of
each integer in a given vector. Fill in the blanks as per the instructions given below:
   • at LINE-1 with appropriate statement to iterate over the given vector v,
   • at LINE-2 with appropriate statement to iterate over the given map hi,
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-09-18, 17:07 IST
Select the Language for this assignment. 
1
#include <iostream>
2
#include <map>
3
#include <vector>
4
5
std::map<int, int> histo(std::vector<int> v){
6
    std::map<int, int> hi; 
7
    for (std::vector<int>::iterator it = v.begin(); it != v.end(); ++it)   //LINE-1
8
        hi[*it]++;
9
    return hi;
10
}
11
12
void print(std::map<int, int> hi){
13
    for (std::map<int, int>::iterator it = hi.begin(); it != hi.end(); ++it)   //LINE-2
14
        std::cout << it->first << ": " << it->second << ", ";
15
}
0
int main() { 
1
    std::vector<int> vec;
2
    for(int i = 0; i < 10; i++){
3
        int a;
4
        std::cin >> a;
5
        vec.push_back(a);
6
    }
7
    std::map<int, int> hi = histo(vec); 
8
    print(hi);  
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
9 4 5 3 4 6 7 4 3 5
3: 2, 4: 3, 5: 2, 6: 1, 7: 1, 9: 1,
3: 2, 4: 3, 5: 2, 6: 1, 7: 1, 9: 1, 
Passed after ignoring Presentation Error
Test Case 2
6 6 7 3 4 5 6 5 4 7
3: 1, 4: 2, 5: 2, 6: 3, 7: 2,
3: 1, 4: 2, 5: 2, 6: 3, 7: 2, 
Passed after ignoring Presentation Error


W10_Programming_Qs.1

Due on 2023-10-05, 23:59 IST
Consider the following program in C++11/14 to convert between feet and inch. Fill in the
blanks as per the instructions given below:
   • at LINE-1 with appropriate header to function convert,
   • at LINE-2 with appropriate return statement convert,
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-10-04, 17:34 IST
Select the Language for this assignment. 
1
#include <iostream>
2
3
class feet; 
4
5
class inch{
6
    public: 
7
        inch(double i) : i_(i){}
8
        feet getValue();
9
        void show(){ std::cout << i_ << " "; }
10
    private:
11
        double i_;
12
};
13
14
class feet{
15
    public: 
16
        feet(double f) : f_(f){}
17
        inch getValue();
18
        void show(){ std::cout << f_ << " "; }
19
    private:
20
        double f_;
21
};
22
23
feet inch::getValue(){
24
    feet t(i_ / 12.0);
25
    return t;
26
}
27
28
inch feet::getValue(){
29
    inch t(f_ * 12.0);
30
    return t;
31
}
32
template <typename T>
33
  
34
decltype(auto) convert(T val)  {     // LINE-1 
35
    return val.getValue();;                  // LINE-2
36
}
0
int main(){
1
    double a, b;
2
    std::cin >> a >> b;
3
    feet f(a);
4
    inch i(b);
5
    inch i1 = convert(f); 
6
    feet f1 = convert(i);
7
    i1.show();
8
    f1.show();
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
12 12
144 1
144 1 
Passed after ignoring Presentation Error
Test Case 2
90 90
1080 7.5
1080 7.5 
Passed after ignoring Presentation Error


W10_Programming_Qs.2

Due on 2023-10-05, 23:59 IST
Consider the following program in C++11/14. Fill in the blanks as per the instructions given
below:
   • at LINE-1 with appropriate header and initialization list for the copy constructor,
   • at LINE-2 with appropriate header for copy assignment operator overload,
   • at LINE-3 with appropriate header and initialization list for the move constructor,
   • at LINE-4 with appropriate header for move assignment operator overload,
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-10-04, 17:36 IST
Select the Language for this assignment. 
1
#include <iostream>
2
#include <vector>
3
4
class number { 
5
    public:
6
        number(){}
7
        number(int i) : ip_(new int(i)) { } 
8
        number(const number& n) : ip_(new int(*(n.ip_) * 10)) { }    // LINE-1: copy constructor 
9
         number& operator=(const number& n) {      // LINE-2: copy assignment 
10
            if (this != &n) { 
11
                delete ip_;  
12
                ip_ = new int(*(n.ip_) * 10); 
13
            } 
14
            return *this;
15
        }
16
        ~number() { delete ip_; } 
17
        number(number&& n) noexcept : ip_(n.ip_ ) { n.ip_ = nullptr; }  // LINE-3: move constructor 
18
        number& operator=(number&& n)noexcept {        // LINE-4: move assignment 
19
            if (this != &n) { 
20
                delete ip_; 
21
                n.ip_ = nullptr; 
22
            } 
23
            return *this;
24
        }
0
void show(){
1
            if(ip_ == nullptr)
2
                std::cout << "moved : ";
3
            else
4
                std::cout << *ip_ << " : ";
5
        }
6
        private:
7
            int* ip_ {nullptr};
8
};
9
10
int main(){
11
    int a;
12
    std::cin >> a;
13
    number n1(a);
14
    number n2 = n1;
15
    number n3;
16
    n3 = n1;
17
    n1.show();
18
    n2.show();
19
    n3.show();
20
    
21
    number n4 = std::move(n1);
22
    number n5;
23
    n5 = std::move(n1);
24
    n1.show();
25
    n4.show();
26
    n5.show();
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
5
5 : 50 : 50 : moved : 5 : moved :
5 : 50 : 50 : moved : 5 : moved : 
Passed after ignoring Presentation Error
Test Case 2
-10
-10 : -100 : -100 : moved : -10 : moved :
-10 : -100 : -100 : moved : -10 : moved : 
Passed after ignoring Presentation Error







W11_Programming_Qs.1

Due on 2023-10-12, 23:59 IST
Consider the following program (in C++11).
   • Fill in the blanks at LINE-1 and LINE-3 with appropriate template definitions.
   • Fill in the blanks at LINE-2 and LINE-4 to complete the return statements for product
     functions.
The program must satisfy the sample input and output.
Select the Language for this assignment. 
1
#include <iostream>
2
3
template <typename T>                   //LINE-1
4
5
double product(T num){  return num; }    //LINE-2
6
7
template <typename T, typename... Tail>         //LINE-3
8
9
double product(T num, Tail... nums){ 
10
11
    return num * product(nums...);         //LINE-4
12
}
0
int main(){
1
    int a, b, c;
2
    double d, e, f;
3
    std::cin >> a >> b >> c;
4
    std::cin >> d >> e >> f;
5
    std::cout << product(a, b, c) << " ";
6
    std::cout << product(d, e, f) << " ";
7
    std::cout << product(a, b, c, d, e, f);
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
2.3 3.4 4.6
24 35.972 863.328
24 35.972 863.328
Passed
Test Case 2
10 20 30
1.5 2.3 -4.5
6000 -15.525 -93150
6000 -15.525 -93150
Passed


W11_Programming_Qs.2

Due on 2023-10-12, 23:59 IST
Consider the program below (in C++11).
   • Fill in the blank at LINE-1 with appropriate template declaration.
   • Fill in the blanks at LINE-2 with an appropriate universal reference type parameter for
     constructor of class derived and an the appropriate call forwarding to the base class
     constructor.
The program must satisfy the given test cases.
Select the Language for this assignment. 
1
#include <iostream>
2
3
class base {
4
    public:
5
        base(const int& n) : n_(n * 10){ std::cout << "lvalue : " << n << ", "; }
6
        base(int&& n) : n_(n * 20) { std::cout << "rvalue : " << n << ", "; }
7
    protected:
8
        int n_;
9
};
10
class derived : public base {
11
    public:
12
         template<typename T>                             //LINE-1
13
14
        derived(T&& n) : base(std::forward<T>(n)) { }        //LINE-2
15
16
        void show(){ std::cout << n_ << " "; }
17
};
0
int main(){
1
    int i;
2
    std::cin >> i;
3
    derived obj1(i);
4
    derived obj2(std::move(i));
5
    obj1.show();
6
    obj2.show();
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
lvalue : 10, rvalue : 10, 100 200
lvalue : 10, rvalue : 10, 100 200 
Passed after ignoring Presentation Error
Test Case 2
50
lvalue : 50, rvalue : 50, 500 1000
lvalue : 50, rvalue : 50, 500 1000 
Passed after ignoring Presentation Error


W11_Programming_Qs.3

Due on 2023-10-12, 23:59 IST
Consider the following program that implements a recursive lambda function to find the sum
of the digits of an input integer.
   • Fill in the blank at LINE-1 to declare the signature of revPrint as std::function.
   • Fill the blank at LINE-2 to complete the definition of lambda function revPrint.
The program must satisfy the sample input and output. 
Your last recorded submission was on 2023-10-07, 22:54 IST
Select the Language for this assignment. 
1
#include<iostream>
2
#include<functional>
3
4
int main() {
5
  std::function<int(int)> revPrint;    //LINE-1
6
7
    revPrint = [&revPrint](int n) -> int {     //LINE-2
8
9
        if (n == 0)
10
            return 0;
11
        
12
        return n % 10 + revPrint(n /= 10);
13
    };
0
int a;
1
    std::cin >> a;
2
    std::cout << revPrint(a);
3
}
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.
   



Private Test cases used for EvaluationStatus
Test Case 1
Passed







2 comments:

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