NPTEL Programming in Modern C++ Programming Assignment 7 September-2023 Swayam

 

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. 
#include<iostream>
#include<cctype>
using namespace std;
class Char{
    char ch;
    public:
         Char(char _ch) : ch(tolower(_ch)){} //LINE-1
 
        operator char(){ return ch; } //LINE-2
 
         operator int(){ return ch - 'a' + 1; } //LINE-3
};
int main(){
    char c;
    cin >> c;
    Char cb = c;
    cout << (char)cb << ": position is " << int(cb);
    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
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. 
#include<iostream>
#include<cstring>
#include<malloc.h>
using namespace std;
class String{
    char* _str;
    public:
        String(char* str) : _str(str){} //LINE-1
        operator char*(){ //LINE-2
            char* t_str = (char*)malloc(sizeof(_str) + 7);
            strcpy(t_str, "Coding is ");
            strcat(t_str, _str);
            return t_str;
        }
};
int main(){
    char s[20];
    cin >> s;
    String st = static_cast<String>(s);
    cout << static_cast<char*>(st);
    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
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. 
#include<iostream>
using namespace std;
class ClassA{
    int a = 10;
    public:
        void display(){
            cout << a << " ";
        }
};
class ClassB{
    int b = 20;
    public:
        void display(){
            cout << b;
        }
        void operator= (int x){ //LINE-1
            b = b + x;
        }
};
 
 
void fun(const ClassA &t, int x){
    ClassA &u =  const_cast<ClassA&>(t); //LINE-2
    u.display();
    ClassB &v = reinterpret_cast<ClassB&>(u); //LINE-3
    v = x;
    v.display();
}
int main(){
    ClassA t1;
    int a;
    cin >> a;
    fun(t1,a);
    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
5
10 15
10 15
Passed
Test Case 2
3
10 13
10 13
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...