NPTEL Programming in C++ Week1 Assignment-1 Solutions 2021 | Swayam





 Ans of w1_Programming_Qs-1


#include <iostream>

#include <string>

using namespace std;


int scmp(string str1, string str2){

    if (str1>str2)    //LINE-1

        return 1;

    else if (str1==str2)     //LINE-2

        return 0;

    else

        return -1;

}


 Ans of w1_Programming_Qs-2


#include <iostream>

using namespace std;


int sum(int x, int y) {

    return x + y;

}

int subtract(int x, int y) {

    return x - y;

}

typedef int Fun_ptr(int ,int);    //LINE-1


int caller(int a, int b, Fun_ptr fp) {     //LINE-2

    return (*fp)(a,b);      //LINE-3

}


 Ans of w1_Programming_Qs-3

  

#include<iostream>

#include<string>

#include<stack>

using namespace std;


stack <string> ss; //LINE-1 


void remove(){

    ss.pop();       //LINE-2

}


int main() {

    string str;

    int n;

    cin >> n;

    for(int i = 0; i < n; i++){

        cin >> str;

        ss.push(str);   //LINE-3

    }

No comments:

Powered by Blogger.