NPTEL Programming in Modern C++ Programming Assignment Week-4 August-2023 Swayam

 

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. 
#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 updateSal(int x) const{ salary += x; } //LINE-2
 
        void print() const{ cout << id << " : " << name << " : " << salary; } //LINE-3
};
int main(){
    string n;
    int i, m, u;
    cin >> i >> n >> m >> u;
    const Employee e1(i, n, m);
    e1.updateSal(u);
    e1.print();
    return 0;
}
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. 
#include<iostream>
using namespace std;
 
class B; //LINE-1
class A{
    int a_ = 0;
    public:
        A(int x) : a_(x) {}
        int mulB (B&);
        int subtractB (B&);
};
class B{
    int b_;
    public:
        B(int y) : b_(y) {  }
 
        friend class A; //LINE-2
};
int A::mulB(B &b) {
    return (a_ * b.b_);
}
int A::subtractB(B &b) {
    return (a_ - b.b_);
}
int main(){
    int x, y;
    cin >> x >> y;
    A t1(x);
    B t2(y);
    cout << t1.mulB(t2) << " " << t1.subtractB(t2);
    return 0;
}
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. 
#include<iostream>
using namespace std;
class Singleton{
    int data;
    static Singleton *ins;                  //LINE-1
    Singleton(int i) : data(i) {}
    public:
        int get(){ return data; }
        static Singleton* createIns(int i){      //LINE-2
            if(!ins)
                ins = new Singleton(i);    //LINE-3
            return ins;
        }
        ~Singleton(){ cout << data; }
};
Singleton *Singleton::ins = 0;
void fun(int x){
    Singleton *s = Singleton::createIns(x+5);
    cout << s->get();
}
int main(){
    int i, j;
    cin >> i >> j;
    Singleton *s = Singleton::createIns(i);
    cout << s->get();
    fun(j);
    return 0;
}
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


No comments

JavaFX Scene Builder

  This is an article about the JavaFX Scene Builder. You will get a short introduction about the installation and usage of the software. The...