NPTEL Programming in Modern C++ Programming Assignment week-8 Sept-2023 Swayam

 

W8_Programming_Qs.1

Due on 2023-09-21, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
    • Fill in the blank at LINE-1 and LINE-2 with appropriate statements for class template specialization.
    • Fill in the blank at LINE-3 with appropriate initializer list.
The program must satisfy the given test cases.
Your last recorded submission was on 2023-09-11, 10:13 IST
Select the Language for this assignment. 
#include<iostream>
#include<cstring>
#include<cstdlib>
 
template<typename T>
class Manipulator{
    T val;
    public:
        Manipulator(T _val = 0) : val(_val) { }
        T deduct(int d){
            T t = val - d;
            return t;
        }
};
template<>    //LINE-1
 
class Manipulator<const char*>  {   //LINE-2   
 
    char* val;
    public:
        Manipulator(const char* _val = 0) : val(strdup(_val)) { }    //LINE-3
        char* deduct(int d){
            char* buf = (char*)malloc(strlen(val) - d + 1);
            int i;
            for(i = 0; i < strlen(val) - d; i++)
                buf[i] = val[i];
            buf[i] = '\0';
            return buf;    
        }
};
int main(){
    int a;
    std::cin >> a;;
    Manipulator<float> f = 100.45;
    Manipulator<const char*> s("programming");
    std::cout << f.deduct(a) << ", ";
    std::cout << s.deduct(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
3
97.45, programm
97.45, programm
Passed
Test Case 2
5
95.45, progra
95.45, progra
Passed


W8_Programming_Qs.2

Due on 2023-09-21, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below.
    • Fill in the blank at LINE-1 with appropriate template declaration for class DataSet.
    • Fill in the blank at LINE-2 with appropriate declaration of array arr.
    • Fill in the blank at LINE-3 with appropriate parameter / parameters for function operator=.
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-09-11, 10:14 IST
Select the Language for this assignment. 
#include <iostream>
 
template<class T, int N>     // LINE-1
class DataSet {
    private:
        T arr[N];            // LINE-2
        int i;
    public:
        DataSet() : i(-1) { }
        void operator=(T data){ // LINE-3
            arr[++i] = data;
        }
void print() {
            for (int j = N - 1; j >= 0; j--)
                std::cout << arr[j] << " ";
        }
};
int main() {
    const int n = 3;
    DataSet<char, n> ds1;
    for (int i = 0; i < n; i++) {
        char j;
        std::cin >> j;
        ds1 = j;
    }
    DataSet<int, n> ds2;
    for (int i = 0; i < n; i++) {
        int j;
        std::cin >> j;
        ds2 = j;
    }
    ds1.print();
    ds2.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
a b c
1 2 3
c b a 3 2 1
c b a 3 2 1 
Passed after ignoring Presentation Error
Test Case 2
x y z
10 20 30
z y x 30 20 10
z y x 30 20 10 
Passed after ignoring Presentation Error


W8_Programming_Qs.3

Due on 2023-09-21, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
   • Fill in the blank at LINE-1 with appropriate constructor for structure Stat.
   • Fill in the blank at LINE-2 with appropriate header declaration for functor.
   • Fill in the blank at LINE-3 with appropriate return statement.
The program must satisfy the given test cases.
Your last recorded submission was on 2023-09-11, 10:14 IST
Select the Language for this assignment. 
#include <iostream>
 
struct Stat {
    int s;
    Stat(int _s) :  s(_s){}  //LINE-1  
    
    double operator() (int arr[], int n) {    //LINE-2   
 
        for(int i = 0; i < n; i++)
            s += arr[i];
        double a = (double)s / n;
 
        return a;                //LINE-3
    }
};
int main(){
    int a, b, c[10];
    std::cin >> a;
    for(int i = 0; i < a; i++){
        std::cin >> b;
        c[i] = b;
    }
    int sum = 0;
    Stat st(sum);
    double avg = st(c, a);
    std::cout << st.s << " " << avg;
    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
4 10 20 30 40
100 25
100 25
Passed
Test Case 2
6 1 2 3 4 5 6
21 3.5
21 3.5
Passed



No comments

File Uploading in PHP

  File Uploading in PHP PHP allow you to upload any type of a file i.e. image, binary or text files.etc..,PHP has one in built global variab...