Home

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

NPTEL Programming in Modern C++ Programming Assignment Jan-2023 Swayam

 Programming In Modern C++


Subscribe to our YouTube Channel :  Swayam Solver


  Please scroll down for latest Programs. 👇 



W3_Programming_Qs-1

Due on 2023-02-16, 23:59 IST
Consider the program below. Fill in the blanks at LINE-1, LINE-2, and LINE-3 
with appropriate keywords such that the program must satisfy the given test cases.
Your last recorded submission was on 2023-02-10, 13:23 IST
Select the Language for this assignment. 
1
#include<iostream>
using namespace std;
class Employee{
    const int id;
    string name;

    mutable int salary; //LINE-1

    public:
        Employee(int a, string b, int c) : id(a), name(b), salary(c) {}

        void updateSalary(int x) const{ salary += x; } //LINE-2

        void print() const{    //LINE-3
0
             cout << id << " : " << name << " : " << salary; 
1
        } 
2
};
3
int main(){
4
    string n;
5
    int i, m, u;
6
    cin >> i >> n >> m >> u;
7
    const Employee e1(i, n, m);
8
    e1.updateSalary(u);
9
    e1.print();
10
    return 0;
11
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
1 Ram 1000
3000
1 : Ram : 4000
1 : Ram : 4000
Passed
Test Case 2
2 Rohit 5000
2000
2 : Rohit : 7000
2 : Rohit : 7000
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed




W3_Programming_Qs-2

Due on 2023-02-16, 23:59 IST
Consider the following program.
  • Fill in the blank at LINE-1 with the appropriate initializer statement for the 
    parameterized constructor,

  • Fill in the blank at LINE-2 with the appropriate statement which deletes the dynamically
    allocated memory to data member arr

The program must satisfy the sample input and output.
Your last recorded submission was on 2023-02-15, 22:23 IST
Select the Language for this assignment. 
1
#include<iostream>
using namespace std;

class Array{
    char *arr;
    int size;

    public:
        Array(int n) : size(n){arr = new char[size];} //LINE-1

        ~Array(){ delete arr; } //LINE-2
0
        void EnterElement(){
1
            for(int i=0;i<size;i++)
2
                cin >> arr[i];
3
        }
4
        void FindMax(){
5
            char max = ' ';
6
            for(int i=0;i<size;i++){
7
                if(max < arr[i])
8
                    max = arr[i];
9
            }
10
            cout << "Max: " << max;
11
        }
12
};
13
int main(){
14
    int n;
15
    cin >> n;
16
    Array a(n);
17
    a.EnterElement();
18
    a.FindMax();
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
3
a s d
Max: s
Max: s
Passed
Test Case 2
5
a e i o u
Max: u
Max: u
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed




W3_Programming_Qs-3

Due on 2023-02-16, 23:59 IST
Consider the program below.
  • Fill in the blank at LINE-1 to complete parameterized constructor
  • Fill in the blank at LINE-2 to complete copy constructor
  • Fill in the blank at LINE-3 to complete return statement
The area( ) evaluates the area of the given right-angled triangle.
The program must satisfy the given test cases. 
Your last recorded submission was on 2023-02-15, 22:31 IST
Select the Language for this assignment. 
1
#include <iostream>
using namespace std;
class triangle{
    int *b, *h;
    public:
        triangle(int _b, int _h) {b = new int(_b); h = new int(_h);} //LINE-1

        triangle(triangle &t) : b(t.b), h(t.h){} //LINE-2

        ~triangle(){ delete b; delete h; }

        int area(){ return 0.5 * *b * *h ; } //LINE-3
};
0
int main(){
1
    int a, b;
2
    cin >> a >> b;
3
    triangle *tri = new triangle(a, b);
4
    cout << tri->area();
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 7
14
14
Passed
Test Case 2
10 20
100
100
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed





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





























































































































 

No comments:

Post a Comment

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