ABOUT THE COURSE :

Summary | |
---|---|
Course Type | Elective |
Duration | 12 weeks |
Category | Computer Science and Engineering |
Start Date | 22 Jan 2024 |
End Date | 12 Apr 2024 |
Exam Registration Ends | 16 Feb 2024 |
Exam Date | 28 Apr 2024 IST |
Assignment Solutions : Programming Assignment :
W9_Programming_Qs-1 :
Consider the following program which takes name and rank of some players, followed by the type of sorting (1 for sort by the length of name and 2 for sort by rank) as input. It prints the players' information in the corresponding sorted order. Complete the program with the following instructions.
• Fill the missing code segments at code segment-1 and code-segment-2 with the ap- propriate overriding of function operator.
The program must satisfy the sample input and output.
struct cmpByName{
//code-segment-1
bool operator()( player& e1, player& e2) {
return e1.get_name().length() < e2.get_name().length();
}
};
struct cmpByRank{
//code-segment-2
bool operator()( player& e1, player& e2) {
return e1.get_rank() < e2.get_rank();
}
};
W9_Programming_Qs-2 :#include <iostream>
#include <map>
#include <list>
std::map<int, int> findFrequency(std::list<int> li){
std::map<int, int> fqMap;
for ( std::list<int>::iterator it = li.begin(); it != li.end(); ++it) //LINE-1
fqMap[*it]++;
return fqMap;
}
void print(std::map<int, int> fq){
for (std::map<int, int>::iterator it = fq.begin(); it != fq.end(); ++it) //LINE-2
std::cout << it->first << " => " << it->second << ", ";
}
W8_Programming_Qs-3 :
Consider the following program that filters the elements from a given list li within a given upper and lower bounds and prints them.
• Fill in the blanks at LINE-1 with appropriate template declaration.
• Fill in the blanks at LINE-2 with an appropriate condition of the while loop.
• Fill in the blanks at LINE-3 with an appropriate call to function find if such that it returns an iterator object to the first element from li that match the given predicate with upper and lower bounds.
The program must satisfy the sample input and output.
template<class T, class Pred> //LINE-1
T find_if(T first, T last, Pred prd) {
while (first != last && !prd(*first)) ++first; //LINE-2
return first;
}
void print(std::list<int> li, int lb, int ub){
boundIt<int> bnd(lb, ub);
std::list<int>::iterator it = find_if(li.begin(), li.end(), bnd); //LINE-3
while(it != li.end()){
std::cout << *it << " ";
it = find_if(++it, li.end(), bnd);
}
}
CRITERIA TO GET A CERTIFICATE :
- Average assignment score = 25% of average of best 8 assignments out of the total 12 assignments given in the course.
- Exam score = 75% of the proctored certification exam score out of 100
- Final score = Average assignment score + Exam score
Follow Us