Home

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

Programming in Modern C++ | Week 5 : Programming Assignments | Jan-2022 | NPTEL | Swayam




If you are using a mobile device then please rotate to landscape orientation for better experience.


Subscribe to our YouTube Channel :  Swayam Solver


Week 5 : Programming Assignment 1

Due on 2022-03-03, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:

• at LINE-1 with appropriate initialization list to initialize the data members,
• at LINE-2 to call printContact(),

such that it will satisfy the given test cases.
Your last recorded submission was on 2022-03-01, 09:00 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
4
class Contact{
5
    private:
6
        int phone_no;
7
        string address;
8
    public:
9
        Contact(int phone_no_, string address_) : phone_no(phone_no_), 
10
                                                      address(address_){}
11
        void printContact(){
12
            cout << "phone: " << phone_no << endl;
13
            cout << "address: " << address << endl;
14
        }
15
};
16
17
class Student : private Contact{
18
    private:
19
        int roll_no;
20
        string name;
21
    public:
22
        Student(int roll_no_, string name_, int phone_no_, string address_) 
23
          : roll_no(roll_no_),name(name_),Contact(phone_no_,address_){}    //LINE-1
void printContact(){
    Contact::printContact();
}   //LINE-2
0
        void print(){
1
            cout << "roll: " << roll_no << endl;
2
            cout << "name: " << name << endl;
3
        }
4
5
};
6
7
int main(){
8
    int a, b;
9
    string s1, s2;
10
    cin >> a >> b;
11
    cin >> s1 >> s2;
12
    Student s(a, s1, b, s2);
13
    s.print();
14
    s.printContact();
15
    return 0;
16
}
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
23 234529
Rajiv Delhi
roll: 23\n
name: Rajiv\n
phone: 234529\n
address: Delhi\n
roll: 23\n
name: Rajiv\n
phone: 234529\n
address: Delhi\n
Passed
Test Case 2
54 239990
Komal Mumbai
roll: 54\n
name: Komal\n
phone: 239990\n
address: Mumbai\n
roll: 54\n
name: Komal\n
phone: 239990\n
address: Mumbai\n
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed









Week 5 : Programming Assignment 2

Due on 2022-03-03, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:

• at LINE-1 and LINE-3 with appropriate inheritance statement,
• at LINE-2 and LINE-4 with appropriate initialization lists,

such that it will satisfy the given test cases.
Your last recorded submission was on 2022-03-01, 09:03 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
4
class Vehicle{
5
    protected: 
6
        int no_of_wheels;
7
    public:
8
        Vehicle(int nw) : no_of_wheels(nw){}
9
        friend ostream& operator<<(ostream& os, const Vehicle& d); 
10
};
11
12
class Car : public Vehicle{    //LINE-1
13
    protected: 
14
        int no_of_passengers;
15
    public:
16
        Car(int nw, int np) : Vehicle(nw),no_of_passengers(np) {} //LINE-2
17
        friend ostream& operator<<(ostream& os, const Car& d); 
18
};
19
20
class Truck : public Vehicle{    //LINE-3
    protected: 
        int load_capacity;
    public:
        Truck(int nw, int lc) : Vehicle(nw),load_capacity(lc) {} //LINE-4
0
        friend ostream& operator<<(ostream& os, const Truck& d); 
1
};
2
3
ostream& operator<<(ostream& os, const Vehicle& ob) { 
4
    os << "no_of_wheels: " << ob.no_of_wheels << endl;
5
    return os;
6
}
7
8
ostream& operator<<(ostream& os, const Car& ob) { 
9
    os << "no_of_wheels: " << ob.no_of_wheels << ", no_of_passengers: " 
10
                   << ob.no_of_passengers << endl;
11
    return os;
12
}
13
14
ostream& operator<<(ostream& os, const Truck& ob) { 
15
    os << "no_of_wheels: " << ob.no_of_wheels << ", load_capacity: " 
16
                << ob.load_capacity << endl;
17
    return os;
18
}
19
20
int main(){
21
    int i, j, k, l, m;
22
    cin >> i >> j >> k >> l >> m;
23
    Vehicle v(i);
24
    Car c(j, k);
25
    Truck t(l, m);
26
    cout << v << c << t;
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
2 4 4 6 20000
no_of_wheels: 2\n
no_of_wheels: 4, no_of_passengers: 4\n
no_of_wheels: 6, load_capacity: 20000\n
no_of_wheels: 2\n
no_of_wheels: 4, no_of_passengers: 4\n
no_of_wheels: 6, load_capacity: 20000\n
Passed
Test Case 2
3 4 6 8 50000
no_of_wheels: 3\n
no_of_wheels: 4, no_of_passengers: 6\n
no_of_wheels: 8, load_capacity: 50000\n
no_of_wheels: 3\n
no_of_wheels: 4, no_of_passengers: 6\n
no_of_wheels: 8, load_capacity: 50000\n
Passed



Private Test cases used for EvaluationStatus
Test Case 1
Passed








Week 5 : Programming Assignment 3

Due on 2022-03-03, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:

• at LINE-1, LINE-2 and LINE-3 with initialization list,
• at LINE-4, LINE-5 and LINE-6 with function definitions,

such that it will satisfy the given test cases.
Your last recorded submission was on 2022-03-01, 09:05 IST
Select the Language for this assignment. 
1
#include<iostream>
2
using namespace std;
3
4
class A{
5
    int a;
6
    public:
7
        A(int _a = 0);
8
        int sum(); 
9
};
10
11
class B : public A{
12
    int b;
13
    public:
14
        B(int _a = 0, int _b = 0);
15
        int sum(); 
16
};
17
18
class C : public B{
19
    int c;
20
    public:
21
        C(int _a = 0, int _b = 0, int _c = 0);
22
        int sum(); 
23
};
24
25
A::A(int _a) : a{_a}{}    //LINE-1
B::B(int _a, int _b) : A{_a} {b=_b;}    //LINE-2
C::C(int _a, int _b, int _c) : B{_a,_b} {c=_c;}    //LINE-3
int A::sum(){ return a; }    //LINE-4 
int B::sum(){ return (A::sum()+b); }    //LINE-5
int C::sum(){ return (B::sum()+c); }    //LINE-6
0
int main(){
1
    int a, b, c;
2
    cin >> a >> b >> c;
3
    A aObj(a);
4
    B bObj(a, b);
5
    C cObj(a, b, c);
6
    cout << aObj.sum() << ", " << bObj.sum() << ", " << cObj.sum();
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 20 30
10, 30, 60
10, 30, 60
Passed
Test Case 2
10 -10 10
10, 0, 10
10, 0, 10
Passed



Private Test cases used for EvaluationStatus
Test Case 1
Passed





Please subscribe to our YouTube Channel :  Swayam Solver

This will help the creator to continue making quality content...

Have a great day !





2 comments:

  1. Replies
    1. Your welcome ! Please subscribe to the channel.
      https://www.youtube.com/channel/UCQ9CBuUITnMxePFSRuyuxwg

      Delete

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