Assignment: interval_map — implement assign Use std::map. Goal: Implement the member function assign for the class template interval_map. The class holds a piecewise-constant mapping from K to V. The internal data structure is: - V m_valBegin; // value for all keys before the first change - std::map m_map; // stores changes of value at certain keys (key -> value starting there) Example representation: For interval_map: M.m_valBegin == 'A' M.m_map == { (1,'B'), (3,'A') } This means the mapping is: key: … -2 -1 0 1 2 3 4 5 … val: A A A B B A A A I.e., values are ‘A’ up to key 1, ‘B’ on [1,3), then back to ‘A’ from 3 onward. You must keep m_map as compact as possible (no redundant entries like ..., (3,'A'), (5,'A'), ... that don’t represent real changes). Constraints: - K must be usable as a key in std::map (requires a strict weak ordering via operator<). - V must be equality-comparable (operator==). Skeleton: #include #include #include template class interval_map { friend void IntervalMapTest(); V m_valBegin; std::map m_map; public: // constructor associates whole range of K with val template interval_map(V_forward&& val) : m_valBegin(std::forward(val)) {} // Assign value val to interval [keyBegin, keyEnd). // Overwrite previous values in this interval. // Conforming to the C++ Standard Library conventions, the interval // includes keyBegin, but excludes keyEnd. // If !(keyBegin < keyEnd), this designates an empty interval, // and assign must do nothing. template void assign(K const& keyBegin, K const& keyEnd, V_forward&& val) requires (std::is_same, V>::value) { // TODO: implement } // look-up of the value associated with key V const& operator[](K const& key) const { auto it = m_map.upper_bound(key); if (it == m_map.begin()) { return m_valBegin; } else { return std::prev(it)->second; } } };
C Engineer Interview Questions
5,469 c engineer interview questions shared by candidates
Difference between class and structure
What is abstract? What's worse, hurting someone's feelings or taking advantage of someone?
Why do you want to work here?
Dot net basic and programming
Not software engineering questions. Sql questions, nothing about oop or programming questions.
Tell me a time something went wrong and you had to act on your feet to come up with a solution Why banking, why PNC
Find the merge point of singly link list.
Print star formation.
what is an interface? what is an abstract class? what are the differences between the two of them? when will you use each one?
Viewing 5271 - 5280 interview questions
See Interview Questions for Similar Jobs
Machine Learning Software EngineerSoftware Development Engineer New GradRobotics Software EngineerSoftware Engineer New GradComputer Science EngineerSystem Software EngineerSoftware Development Engineer Server SideAlgorithm EngineerSoftware Design EngineerEntry Level Software Development EngineerJunior Software Development EngineerSoftware Developer New GradSoftware Engineer CcEmbedded Software DeveloperGraphics Software EngineerSoftware Engineer Entry LevelEngineer SoftwareData Science Software Engineer