An Introduction To Programming Through C++ Assignment 11 Answers

NPTEL An Introduction To Programming Through C++ Assignment 11 Answers 2022:-In This article, we have provided the answers to An Introduction To Programming Through C++ Assignment 11. You must submit your assignment with your own knowledge.

What is An Introduction to Programming Through C++?

This course provides an introduction to problem-solving and programming using the C++ programming language. The topics include:

  • Basic programming notions. Control flow, variables and assignments statements, conditional execution, looping, function calls including recursion. Arrays and structures. Elementary aspects of classes. Heap memory. 
  • Program design. How human beings solve problems manually. Strategies for translating manual strategies to computer programs. Organizing large programs into units such as functions and classes. Introduction to assertions and invariants.
  • Programming applications. Arithmetic on polynomials, matrices. Root finding. Sorting and searching. Design of editors and simulators, including graphical editors. Elementary animation. A rudimentary graphics system will be discussed.
  • Standard Library of C++. The string, vector and map classes.

CRITERIA TO GET A CERTIFICATE

Average assignment score = 25% of the 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

YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF THE AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.

An Introduction To Programming Through C++Answers
Assignment 1Click Here
Assignment 2Click Here
Assignment 3Click Here
Assignment 4Click Here
Assignment 5Click Here
Assignment 6Click Here
Assignment 7Click Here
Assignment 8Click Here
Assignment 9Click Here
Assignment 10Click Here
Assignment 11Click Here
Assignment 12Click Here

NPTEL An Introduction to Programming Through C++ Assignment 11 Answers 2022:-

Q1. What’s printed by the following code fragment?

set<int> s;
s.insert(100);
s.insert(25);
for(auto e : s) cout << e;

Answer:- 25100

Answers will be Uploaded Shortly and it will be Notified on Telegram, So JOIN NOW

An Introduction To Programming Through C++ Assignment 11 Answers

Q2. What is printed by the following code

map<int,int> m;
m[50] = 24;
m[3] = 77;
for (auto e : m) cout << e.first << e.second;

Answer: 3775024

Q3. Suppose during a certain execution, 5 reallocations happened due to push backs on a certain vector. What is the minimum number of elements that the vector must have at the end of the execution?

Answer: 65

Q4. How many copying operations (overhead) must have happened during the execution?

Answer: 124

Q5. Suppose at a certain time during execution a vector has 100 elements (i.e. there have been 100 pushbacks). How many more push backs can there be without causing a reallocation?

Answer: 28

👇FOR NEXT WEEK ASSIGNMENT ANSWERS👇

An Introduction To Programming Through C++ Assignment 11 Answers

Q6. Answer T if you think the following statement is true and F if false:
The total number of copying operations performed as a part of reallocation is less than twice the number of elements in the vector (i.e. the number of elements pushed back).

Answer:- T

Q7. Answer T if you think the following statement is true and F if false:
The amount of memory allocated to a vector that is not in use to store elements is less than the amount of memory that is being used to store elements, i.e. the memory in use is more than the memory not in use.

Answer: T

Consider the following code fragment.

map<string, set<string>> friends;
friends[“Dharmendra”].insert(“Amitabh”);
friends[“Dharmendra”].insert(“Vinod”);
cout << friends[“Dharmendra”].count(“Amitabh”) << endl;
cout << friends[“Dharmendra”].size() << endl;

Q8. What number is printed first?

Answer: 1

Q9. What number is printed second?

Answer: 2

If there are any changes in answers will notify you on telegram so you can get a 100% score, So Join

Q10. I have information about which cities are in which countries. Using this information I want to write a program that answer questions of the form: (a) Is a city X in country Y. (b) Which cities are in country Y. What data structure is most convenient for representing the required information?

  • A map mapping each country to a vector containing cities in that country. 
  • A map mapping each country to a set containing cities in that country. 
  • A map mapping each city to the country in which it is present.

Answer: b

Programming Assignment Answers:-

Q1. In processing documents, we often build something called an index, or an inverted index. This is simply a set of pairs (word, occurrences)where word is a word occurring in the document, and occurrences is a sequence of integers giving the positions (in increasing order) at which theword occurs. You are to write a program which takes a document as input and prints the index for it, with the words in ascending order (lexicographically).

Code:-

int main()
{
  string s;
   
  int i=0,second;
  bool end=false;
  map<string,vector<int>>word;
  while(!end)
  {
    cin>>s;
    if(s[s.size()-1]=='.')
    {
      s.resize(s.size() - 1);
      end=true;
    }
    
    word[s].push_back(i++);
  }
  for(auto it:word)
  {
    cout<<it.first;
    for(auto index:it.second)
      cout<<' '<<index;
    cout<<endl;
  }
  return 0;
}

Q2. In the lectures we discussed a way to store a fare table: a fare table gives the fare between two cities, and is stored in the following data structure:

Code:-

map<string ,map<string,double>> faretable;
int findfare(string c1,string c2)
{
  map<string, map<string, double> >::iterator itr;
  map<string, double>::iterator ptr;
  for(itr = faretable.begin(); itr != faretable.end(); itr++)
  {

     for(ptr = itr->second.begin(); ptr != itr->second.end();  ptr++)
        {
          if((itr->first==c1 && ptr->first==c2)||(itr->first==c2 && ptr->first==c1))
            
          {
            return ptr->second;
          }
        }
  }
  
  return 0;
}

int main()
{
  string s,c1,c2,c;
  
  double f;
  bool end=false;
  int flag;
  
  map<string, map<string,double> >::iterator itr,itr1;
  map<string,double>::iterator ptr,ptr1;
  
  while(!end)
  {
    cin>>s;
    
    if(s=="Insert")
    {

       cin>>c1>>c2>>f;
      faretable[c1][c2]=f;
    }
    else if(s=="Fare")
    {
      cin>>c1>>c2;
      flag=findfare(c1,c2);
      if(flag==0)
        cout<<"unknown"<<endl;
      else
        cout<<flag<<endl;
    }
    else if(s=="Onechange")
    {
      cin>>c1>>c2;
      flag=findfare(c1,c2);
      if(flag!=0)
        cout<<flag<<endl;
      
      else
      {
        for(itr=faretable.begin(); itr!= faretable.end(); itr)
        {
          for(ptr=itr->second.begin(); ptr!=itr->second.end(); )
              {
                if(c1==itr->first)
                {
                  c=ptr->first;
                  flag=findfare(c,c2);
                  if(flag==0)
                    continue;
                  else 
                    goto L;
                }
              }
            }
          }
    L:if(flag==0)
              cout<<"impossible"<<endl;
              else
              cout<<(flag+ptr->second)<<endl;
              }
              
              else
              
              end=true;
              }
              return 0;
              }

Disclaimer:- We do not claim 100% surety of solutions, these solutions are based on our sole expertise, and by using posting these answers we are simply looking to help students as a reference, so we urge do your assignment on your own.

For More NPTEL Answers:- CLICK HERE

Join Our Telegram:- CLICK HERE

NPTEL An Introduction To Programming Through C++ Assignment 11 Answers 2022:-In This article, we have provided the answers to An Introduction To Programming Through C++ Assignment 11. You must submit your assignment with your own knowledge.

1 thought on “An Introduction To Programming Through C++ Assignment 11 Answers”

Leave a Comment