![NPTEL-Programming-In-Modern-C-Week12-Assignment-Solution-2023](https://techiestalk.in/wp-content/uploads/2023/10/NPTEL-Programming-In-Modern-C-Week12-Assignment-Solution-2023-1024x576.jpg)
There has been a continual debate on which programming language/s to learn, to use. As the latest TIOBE Programming Community Index for August 2021 indicates – C (13%), Python (12%), C++ (7%), Java (10%), and C#(5%) together control nearly half the programming activities worldwide. Further, C Programming Language Family (C, C++, C#, Objective C etc.) dominate more than 25% of activities. Hence, learning C++ is important as one learns about the entire family, about Object-Oriented Programming and gets a solid foundation to also migrate to Java and Python as needed. C++ is the mother of most general purpose of languages. It is multi-paradigm encompassing procedural, object-oriented, generic, and even functional programming. C++ has primarily been the systems language till C++03 which punches efficiency of the code with the efficacy of OOP. Then, why should I learn it if my primary focus is on applications? This is where the recent updates of C++, namely, C++11 and several later offer excellent depths and flexibility for C++ that no language can match. These extensions attempt to alleviate some of the long-standing shortcomings for C++ including porous resource management, error-prone pointer handling, expression semantics, and better readability. The present course builds up on the knowledge of C programming and basic data structure (array, list, stack, queue etc.) to create a strong familiarity with C++98 / C++03. Besides the constructs, syntax and semantics of C++ (over C), we also focus on various idioms of C++ and attempt to go to depth with every C++ feature justifying and illustrating them with several examples and assignment problems. On the way, we illustrate various OOP concepts. The course also covers important advances in C++ 11 and later released features..
Programming In Modern C++ Week12 Programming Assignment July 2023
INTENDED AUDIENCE : Any interested audience
PREREQUISITES : 10th standard/high school
INDUSTRY SUPPORT : Programming in C++ is so fundamental that all companies dealing with systems as well as application development (including web, IoT, embedded systems) have a need for the same. These include – Microsoft, Samsung, Xerox, Yahoo, Oracle, Google, IBM, TCS, Infosys, Amazon, Flipkart, etc. This course would help industry developers to be up-to-date with the advances in C++ so that they can remain at the state-of-the-art.
Course Layout
Course Name : Programming In Modern C++ July 2023
Programming Assignment : Q1
#include
#include
struct Factorial{
Factorial(const long long& n) : n_( n) { }
long long operator()() { //LINE-1
long long f = 1;
if(n_ == 0 || n_ == 1)
return 1;
for(int i = 1; i <= n_; i++)
f *= i;
return f;
}
const long long n_;
};
long long callFacto(int n){
auto a = std::async(Factorial(n)); //LINE-2
return a.get(); //LINE-3
}
int main() {
int n;
std::cin >> n;
std::cout << callFacto(n);
return 0;
}
Course Name : Programming In Modern C++ July 2023
Programming Assignment : Q2
#include
#include
namespace DS{
template
class deque;
template
class node{
public:
node(T2 _info) : info(_info), next(nullptr) {}
friend deque;
private:
T2 info;
std::shared_ptr> next;
std::weak_ptr> prev;
};
template
class deque{
public:
deque() = default;
void addFront(const T1& item){
std::shared_ptr> n = std::make_shared>(item);
if(first == nullptr){
first = n;
last = first;
}
else{
n->next = first;
first->prev = n;
first = n;
}
}
void addEnd(const T1& item){
std::shared_ptr> n = std::make_shared>(item);
if(first == nullptr){
first = n;
last = first;
}
else{
std::shared_ptr> t = first;
for(; t->next != nullptr; t = t->next); //LINE-1
t->next = n;
n->prev = t;
last = n;
}
}
void traverse(){
for(std::shared_ptr> t = first; t != nullptr; t = t->next) //LINE-1
std::cout << t->info << " ";
}
void rev_traverse(){
for(std::shared_ptr> p = last; p != nullptr; p = p->prev.lock()) //LINE-2
std::cout << p->info << " ";
}
private:
std::shared_ptr> first { nullptr };
std::shared_ptr> last { nullptr };
};
}
int main(){
DS::deque il;
int n, a;
std::cin >> n;
for(int i = 0; i < n; i++){
std::cin >> a;
il.addFront(a);
}
for(int i = 0; i < n; i++){
std::cin >> a;
il.addEnd(a);
}
il.traverse();
std::cout << std::endl;
il.rev_traverse();
return 0;
}