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

 

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. 
#include <iostream>
using namespace std;
class Vehicle{
    string vehicleName;
    int noOfWheels;
    protected:
        Vehicle(string s, int w) : vehicleName(s), noOfWheels(w) { }
    public:
        friend void vehicleDetails(const Vehicle&); //LINE-1
};
class Twowheeler : public Vehicle{
    public:
        Twowheeler(string n) : Vehicle(n,2) { } //LINE-2
};
class Fourwheeler : public Vehicle{
    public:
        Fourwheeler(string n) : Vehicle(n,4) { } //Line-3
};
void vehicleDetails(const Vehicle &v){
    cout << v.vehicleName << ": ";
    if(v.noOfWheels == 2)
        cout << "Two Wheeler";
    else if(v.noOfWheels == 4)
        cout << "Four Wheeler";
}
int main(){
    string s;
    int n;
    Vehicle *v;
    cin >> s >> n;
    if(n==2)
        v = new Twowheeler(s);
    else if(n==4)
        v = new Fourwheeler(s);
    vehicleDetails(*v);
    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
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. 
#include<iostream>
using namespace std;
class B1{
    protected:
        int b1;
    public:
        B1(int b) : b1(b){}
};
class B2{
    protected:
        int b2;
    public:
        B2(int b) : b2(b){}
};
class D : public B1, public B2 { //LINE-1
 
    int d;
 
public:
 
    D(int x) : d(x), B1(x+5), B2(x+10) {} //LINE-2
void show(){
        cout << d << ", " << b1 << ", " << b2;
    }
};
int main(){
    int x;
    cin >> x;
    D t1(x);
    t1.show();
    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
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





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...