InterviewSolution
Saved Bookmarks
| 1. |
What is upcasting and downcasting? What is object slicing in case of upcasting? |
|
Answer» A Sparse Matrix is an array of elements in which many elements have a value of zero. #include <string.h> #include <iostream> #include <map> #include <utility> using namespace STD; int MAIN() { map<int, string> Employees; // 1) Assignment using array index NOTATION Employees[5234] = "Mike C."; Employees[3374] = "Charlie M."; Employees[1923] = "David D."; Employees[7582] = "John A."; Employees[5328] = "Peter Q."; cout << "Employees[3374]=" << Employees[3374] << endl << endl; cout << "Map size: " << Employees.size() << endl; cout << endl << "Natural Order:" << endl; for( map<int,string>::iterator ii=Employees.begin(); ii!=Employees.end(); ++ii) { cout << (*ii).first << ": " << (*ii).SECOND << endl; } cout << endl << "Reverse Order:" << endl; for( map<int,string>::reverse_iterator ii=Employees.rbegin(); ii!=Employees.rend(); ++ii) { cout << (*ii).first << ": " << (*ii).second << endl; } }Output: Employees[3374]=Charlie M. Map size: 5 Natural Order: 1923: David D. 3374: Charlie M. 5234: Mike C. 5328: Peter Q. 7582: John A. Reverse Order: 7582: John A. 5328: Peter Q. 5234: Mike C. 3374: Charlie M. 1923: David D. |
|