NPTEL Programming in Modern C++ Programming Assignment Week-3 Programming Assignments July-2023 Swayam

 

W2_Programming_Qs.3

Due on 2023-08-10, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
   • at LINE-1 with appropriate function header,
   • at LINE-2 with appropriate return statement
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-07-30, 13:24 IST
Select the Language for this assignment. 
#include <iostream>
using namespace std;
struct point {
    int x, y;
};
point operator+ ( point& pt1, point& pt2) { //LINE-1
 
    pt1.x += pt2.x;
    pt1.y += pt2.y;
 
    return pt1;    //LINE-2
}
int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    point p1 = {a, b};
    point p2 = {c, d};
    point np = p1 + p2;
    cout << "(" << p1.x << ", " << p1.y << ")" << "(" << np.x << ", " << np.y << ")";
    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 3 4
(4, 6)(4, 6)
(4, 6)(4, 6)
Passed
Test Case 2
2 4 6 8
(8, 12)(8, 12)
(8, 12)(8, 12)
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed



W3_Programming_Qs.1

Due on 2023-08-17, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below:
    • Complete two constructor statements at LINE-1 and LINE-2,
    • Complete the return statement at LINE-3 to calculate the manhattan distance between two points,
such that it will satisfy the given test cases.
Your last recorded submission was on 2023-08-08, 22:30 IST
Select the Language for this assignment. 
#include<iostream>
#include<cmath>
using namespace std;
 
class Point{
    const int x,y;
 
public:
    Point(int _x=0, int _y=0) : x(_x), y(_y) {} //LINE-1
 
    Point(const Point& p) : x(p.x), y(p.y) {} //LINE-2
 
    double distance(Point p){
 
        return abs((p.x-x)) + abs((p.y - y)) ; //LINE-3
    }
void print(){ cout << "(" << x << "," << y << ")" << endl; }
 
};
 
int main(){
    int x1,x2,y1,y2;
    cin >> x1 >> y1 >> x2 >> y2;
 
    Point p1(x1,y1), p2(x2,y2);
    p1.print();
 
    p2.print();
    cout << "Distance: " << p1.distance(p2);
 
    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 3 4
(1,2)\n
(3,4)\n
Distance: 4
(1,2)\n
(3,4)\n
Distance: 4
Passed
Test Case 2
1 -1 2 -2
(1,-1)\n
(2,-2)\n
Distance: 2
(1,-1)\n
(2,-2)\n
Distance: 2
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed


W3_Programming_Qs.2

Due on 2023-08-17, 23:59 IST
Consider the following program. Fill in the blanks as per the instructions given below.
    • at LINE-1 with constructor definition,
    • at LINE-2 with appropriate statement to deallocate array memory
such that it will satisfy the given test cases. 
Your last recorded submission was on 2023-08-08, 22:31 IST
Select the Language for this assignment. 
#include<iostream>
using namespace std;
 
class Array{
    int *arr;
    int size;
 
public:
    Array(int n) : size(n) { arr = new int[n]; } //LINE-1
 
    ~Array(){ delete arr; } //LINE-2
void Enter(){
        for(int i=0;i<size;i++)
            cin >> arr[i];
    }
    void FindMin(){
        int min = 999;
        for(int i=0;i<size;i++){
            if(min > arr[i])
                min = arr[i];
        }
        cout << "Min: " << min;
    }
};
int main(){
    int n;
    cin >> n;
    Array a(n);
    a.Enter();
    a.FindMin();
    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
1 3 5 8
Min: 1
Min: 1
Passed
Test Case 2
3
7 3 9
Min: 3
Min: 3
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed


W3_Programming_Qs.3

Due on 2023-08-17, 23:59 IST
Consider the following program. Fill in the blanks at LINE-1, LINE-2 and LINE-3 with
Consider the following program. Fill in the blanks at LINE-1, 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-08, 22:31 IST
Select the Language for this assignment. 
#include<iostream>
using namespace std;
class Student{
    const int sid;
    string sname;
 
    mutable int marks; //LINE-1
 
    public:
        Student(int a, string b, int c) : sid(a), sname(b), marks(c) {}
 
        void updateMarks(int x) const { marks += x; } //LINE-2
 
        void print() const {    //LINE-3
cout << sid << " : " << sname << " : " << marks; 
        } 
};
 
int main(){
    string n;
    int i, m, u;
    cin >> i >> n >> m >> u;
    const Student s1(i, n, m);
    s1.updateMarks(u);
    s1.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 36 5
1 : Raj : 41
1 : Raj : 41
Passed
Test Case 2
2 Amal 48 20
2 : Amal : 68
2 : Amal : 68
Passed




Private Test cases used for EvaluationStatus
Test Case 1
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...