B.Tech. (I) - ICP-132 (2009) Assignment 1 Level 0 ------- 1. Read two strings and print the number of characters present in them. Eg Input: Helo 1233h3 Output: 4 6 2. Read three strings and print them in dictionary order Eg Input: efd x eda Output: eda efd x 3. Read three real numbers x, y and z and print the value of (x^2*y)/z. Input: 2.1 0.7 0.3 Output: 10.29 Level 1 ------- 1. Print the smallest and largest values that your compiler can support for int, short int, float, double and char. Print the precision of float and double. How is precision defined? (Hint: See https://iws60.iiita.ac.in/wiki/cpp/doku.php?id=dgg:ch_02:ranges ) 2. Read two numbers x and y and using only one "cout" print if they are even or odd. Eg Input: 2 3 Output: even odd 3. Read 3 integers and print the smallest of char, short int, int or long int that will be able to hold the values. The type could be unsigned if the number is non-negative. Give preference to signed over unsigned. Eg Input: 5 187 4294967295 Output: char short int unsigned int Level 2 ------- 1. Write a program to show 5 different ways to create a string. 2. Write a program that creates a string that is made of first 3 characters of two input strings. Eg: Input: 4562332423 ffdsfg Output: 456ffd 3. Two strings have values "32" and "123.21". Convert them into int and float and print the values when 10 is added to them (ie print numbers 42 and 133.21). Level 3 ------- 1. Write a C++ program that takes 3 integers as input and prints if they are divisible by 2, 3 or 6. If the number is divisible by more than one of the three it should print the greater of all. The number of digits could be 1000. Eg Input: 2 12345678901234567890123456789012345678901234567890 9 Output: 2 6 3 2. Given three string of 5 letters, print the number of distinct number of letters. Eg Input: abccb edasf aavav Output: 3 5 2 3. Print the gap number of letters between the letters X and Y in a given string. Input: abcXijklmYsada Output: 5 B.Tech. (I) - ICP-132 (2009) Assignment 2 Level 0 ------- 1. Read two integers and print numbers from the lower integer to the higher Input: 10 6 Output: 6 7 8 9 10 2. Read 'n' real numbers and print the maximum. First input is 'n'. Eg Input: 5 1.0 10.2 2.4 -4.2 2.5 Output: 10.2 3. Find average of 'n' numbers. Input: 3 0.7 0.3 2.5 Output: 1.1667 Level 1 ------- 1. Read integer 'n' and a string 's' print 's' n-times. Input: 4 sda Output: sdasdasdasda 2. Given a string print the number of letters in between 'X' and 'Y'. Print -ve if 'Y' comes earlier to 'X'. Input: abXabcdeY Output: 5 3. Print the first 'n' numbers in Fibonocci series. Given: Fib(n)=Fib(n-1)+Fib(n-2); Fib(0)=0; Fib(1)=1 Input: 10 Output: 0 1 1 2 3 5 8 13 21 34 Level 2 ------- 1. Find standard deviation of 'n' numbers. (Normalise by N-1) Input: 3 0.7 0.3 2.5 Output: 1.179 2. Given a string, print ASCII values of each letter. Input: AbC Output: 65 98 67 3. Given a string, find the mod 10 of sum of all ASCII values. Input: AB Output: 1 Level 3 ------- Read http://acm.uva.es/problemset/float-in-competition.pdf 1. Fix the bug in the following program: --- #include using namespace std; int main() { float D; D=0.1; while ( 1.0-D != 0.0 ) { cout << D << endl; D=D+0.1; } return 0; } --- 2. Write a program that correctly prints the shorter of the two paths, AOB and COD, where O is the origin; points A, B, C and D are successively (2, 5, 31), (1,2,9), (0, 7, 27) and (1,8,10). 3. Given 'n' strings, print them in dictionary order. Input: 4 who knows? hello world a I am the best! :) Output: I am the best! :) a hello world who knows? B.Tech. (I) - ICP-132 (2009) Assignment 3 Level 0 ------- 1. Given natural numbers x and y construct a vector with numbers 1^2, 2^2,...,(x-1)^2,(x+1)^2,(x+2)^2,...y^2. Find the average value. 2. Read 'n' numbers and print the median, mode and range. 3. Find maximum of 'n' strings. Input: 3 hello world yes Output: world Level 1 ------- 1. Numbers 1^2, 2^2,...,(x-1)^2,(x+1)^2,(x+2)^2,...y^2 are given. Find x and y using a function. Input: 1 4 9 25 36 Output: x=4 y=6 2. Logistic function is given as X_n+1 = G.(X_n).(1-X_n), where X_n is the population in n'th year and X_n+1 is the population in (n+1)th and G is the growth constant. It is used in ecology to model population of predetor prey systems, where their numbers and growth constant show interesting dynamics. For G in range (1,3) population will reach a stable value while more complicated results appear from higher G. For a given X_0 and G as initial values, find the average population of predetor between (n-50) and n years. 3. Given nxn matrices A and B, find A*B' Level 2 ------- 1. Insert x^2 into its correct place as mentioned in Level 1 prob 1. 2. Using Lagrange interpolation formula, find sin(49) using sin(10), sin(10), sin(20), sin(33), sin(45), sin(48), and sin(57). Using math library find the difference from the actual value. 3. Given a vector write a function to sort it in descending order. Level 3 ------- (See "Introduction to Algorithms", by TH Corman, CE Leiserson, RL Rivest) 1. Implement a Queue on a vector v of integers. The functions to be built are: void enqueue(v, i), where i is the number to be enqueued int dequeue(v), int size(v), int front(v), 2. An nxn matrix (D) is given that shows the distance between any two cities. Using Floyd-Warshall algorithm, find the shortest between any two cities. 3. Task scheduling problem: Given n tasks and their completion times the best way to process jobs is using a 'greedy technique' in such a way that the tasks with fastest completion times are taken up earlier. Given a set of n tasks and their completion times, print the order in which tasks should be taken up. B.Tech. (I) - ICP-132 (2009) Assignment 4 Level 0 ------- 1. Given natural numbers x and y construct a list with numbers 1^2, 2^2,...,(x-1)^2,(x+1)^2,(x+2)^2,...y^2. Find the average value from the stored list using a function. 2. Copy list created as in problem 1 into a new list (a) using a function, and (b) without using a function. 3. Make a list of first 10 prime numbers. Level 1 ------- 1. Make a list of vectors that contains two vectors such that: a. first vector has first 10 positive odd numbers, and b. second vector has first 15 postive even numbers. Print all the numbers stored. 2. Make a vector of list such that: a. first list has first 10 positive odd numbers, and b. second list has first 15 postive even numbers. Print all the numbers stored. 3. Let L1 and L2 be two lists such that: L1 = 1 -> 2 -> 3 -> 4 -> 5 L2 = 15 -> 14 -> 13 -> 12 -> 11. Create a list L3 = L1 + L2 such that: L3 = 1 -> 2 -> 3 -> 4 -> 5 -> 15 -> 14 -> 13 -> 12 -> 11 Level 2 ------- 1. Insert x^2 into its correct place as mentioned in Level 0 prob 1 in a given list. 2. Let L1 and L2 be two lists such that: L1 = 1 -> 2 -> 3 -> 4 -> 5 L2 = 15 -> 16 -> 17 -> 18 -> 19. Create a list L3 = L1 + L2 such that: L3 = 16 -> 18 -> 20 -> 22 -> 24 3. A stack is a data structure which is opposite to queue. Which ever element comes last will be the first to move out. Using a list L of integers, implement functions given below a. void push(L, i), where i is the number to be enqueued b. int pop(L), returns the last element put in the stack c. int size(L), returns the number of elements in the stack L d. int top(L), returns the element that will be popped next in L Level 3 ------- 1. Use a list L to implement a queue as given in Asssignment 3. 2. Given a list with several elements, insert elements 1 to 10 at i'th element. 3. Given a list of integers, remove all the duplicates using a function uniq(L). B.Tech. (I) - ICP-132 (2009) Assignment 5 Level 0 ------- 1. Read 2 mobile numbers and roll numbers and print them using maps. Eg Input: 3753215444 God 005345545423 Lord Output: 3753215444 God 5345545423 Lord 2. A DNS table associates URL with Ip no.s. Given the following DNS table, print the IP for a given URL. Eg DNS Table: yahoo.com 206.190.60.37 google.com 72.14.207.97 google.com 72.14.207.97 mail.google.com 72.14.207.97 rediff.com 204.2.177.16 Input: google.com Output: 72.14.207.99 3. Given the SR No. of a student, print the name Data: MIR2009120 ABC MIR2009567 XYZ MIR2009657 IJK Input: MIR2009567 Output: XYZ Level 1 ------- 1. A sparse matrix is a matrix with very few non-zero elements. Given a sparse matrices A and B of order 100x100, print C=A+B. You shall be given only the non-zero elements and must print only the non-zero elements. All elements which are zero should not be stored or printed! Data: A: A(1,90) = 10 A(2,10) = 70 A(5,20) = 20 B: B(1,90) =-10 B(2,10) = 10 B(5,20) = 50 B(7,10) = 10 Output: C(2,10) = 20 C(5,20) = 70 C(7,10) = 10 2. Store the following data in a memory as a map and print it as a table. It consists of SR No., marks and you must find the average. Eg Data: IMB2009123 80.0 93.5 91.5 IMB2009124 87.5 53.0 71.0 IMB2009125 81.5 83.0 41.5 Input: IMB2009124 Output: IMB2009124 87.5 53.0 71.0 70.5 3. You are given movie names, name of Director, Producer, Hero(s) and Heroine(s). Given the movie name, print the names of the heros. Eg Data: Movie Name: Fool N Final Producer: Firoz A. Nadiadwala Director: Ahmed Khan Hero: Sunny Deol, Shahid Kapur, Suniel Shetty, Jackie Shroff Heroine: Ayesha Takia Movie Name: Dharm Producer: Sheetal Vinod Talwar Director: Bhavna Talwar Hero: Pankaj Kapoor Heroine: Supriya Pathak Input: Dharm Output: Pankaj Kapoor Level 2 ------- 1. Perform sparse matrix multiplication of two sparse matrices of order 100x100. 2. You are given number plates of vehicles in which the leading letters indicate states. Print all the number plates of UP. Eg: Data: AP12 3423 BH45 431 KN63 355 UP70 6533 UP92 3423 Output: UP70 6533 UP92 3423 3. You are given first name and last names of 5 people of which two have same first name and three share the last name. Find if any of them have both first and last names as same using map! Level 3 ------- 1. Huffman decoding is done using a lookup table. Each letter has a binary code associated and the length could be different. The decoding starts from the left side as shown below. Given the table, decode a text message. Eg Data: T 10 S 00 01 I 110 E 1110 H 11110 A 11111 Input: 10111101100001110000111111011011100010 (Should be split as "10 11110 110 00 01 110 00 01 11111 01 10 1110 00 10") Output: THIS IS A TEST 2. Given actor name in 1.3, print the movie name(s). 3. Given the IP no as in 0.2, print all the URLs with the same IP. B.Tech. (I) - ICP-132 (2009) Assignment 6 Level 0 ------- 1. Make a class called "point" with two integer data members x and y. Show how to create and use two points p1 and p2. 2. Create a student record class "st_rec" that has the following data members: SR No., Name, marks in ICP, SDC, EDC, PHY, MAT and CSL, and Semester grade. Show how to use it. 3. Create a "human" class with private data members Age and Salary and public data members Father and Mother. Show how to set the values of Age and Salary using a constructor. Level 1 ------- 1. Using the Point class as mentioned above, write a function to compute distance between the points p1 and p2. 2. In the class "st_rec" as above, add a method that computes grade based on the total marks as follows if ( failed in any subject ) grade = "F" else if ( total < 40% ) grade ="F" else if ( total < 50% ) grade ="D" else if ( total < 60% ) grade ="C" else if ( total < 70% ) grade ="B" else if ( total < 80% ) grade = "B+" else if ( total < 90% ) grade = "A" else grade = "A+" 3. Write methods to see and modify Age and Salary in the class "human". Level 2 ------- 1. Create a class p4 with which can store 4 points (x1,y1) through (x4,y4). Write the following methods. dist: prints distance between first 2 points angle: prints angle between first 3 points area: finds area of the quadilateral enclosed by the 4 points closest: finds the point closest to origin 2. Write a class "Hello" with a method "helo" that prints "Hello!". It should also have a method "count" that gives the number of times the method "helo" was called. No other public data member or public method is allowed apart from "helo" and "count". 3. Create a class "Poll" that has a question "Q" and methods "yes", "no" and "results". The following rules are to be followed: 1. The programmer should be able to vote using "yes" or "no" 2. Once "results" method is called, results are shown. 3. After results are shown, "yes" and "no" methods will not change results and an error message is printed that the poll is over! Level 3 ------- Read operator overloading on classes, at least for '<'. See "Sample Code" in the Wiki. 1. Create a vector of objects of class "points" and put 5 objects. Sort the objects (points) as per the following rule: if ( x1 < x2 ) p1 < p2 else if ( y1 < y2 ) p1 < p2 else p1 > p2 2. Create an class with a list as a data member. Add two objects where addition is defined as sum of corresponding list elements. Hence if ob1 has a list <1, 2> and ob2 <7, 5, 4> then the result is ob3=ob1+ob2 where ob3 has a list <8, 7, 4>. Missing elements are treated as zero as in the case of the third element. 3. Create a class "Matrix" that can store a nxm matrix where n and m are user specified. Define an operator '*' so that the result is matrix multiplication. B.Tech. (I) - ICP-132 (2009) Assignment 7 Level 0 ------- 1. Given a number n by the user, create a file data_n.txt with each line having i, i^2 and i^3. If the file data_n.txt already exists, the program should print error message and quit. Eg Input: 5 Output: (file data_n.txt) 1, 1, 1 2, 4, 8 3, 9, 27 4, 16, 64 5, 25, 125 2. Remove the commas from the data_n.txt. If the file data_n.txt does not exist, then the program should print the error message and quit. 3. Write a program that reads data_n.txt and appends it to a file data_an.txt. The program should create data_an.txt if it is not found and should print a message that the file has been created. Level 1 ------- 1. Manually remove the second line from data_n.txt. Write a program to print the missing lines in data_n.txt. 2. A user enters multiple integers in three lines. Print the number of integers in each line and print their value doubled. The numbers are white space separated. Eg Input: 5 3 2 2 1 23 2 1 Output: 4: 10 6 4 4 1: 2 3: 46 4 2 3. A user enters multiple reals in three lines. Print the number of reals in each line and print their value doubled to single decimal accuracy. The numbers are comma separated. Eg Input: 5.1,3.2,2.1,2.1 1.0 22.5,3.4,1.0 Output: 4: 10.2 6.4 4.2 4.2 1: 2.0 3: 45.0 6.8 2.0 Level 2 ------- A data base is a collection of records. A record is a collection of fields. The following questions are based on two data bases, SwissProt and Nasdaq. The files are available at: https://iws60.iiita.ac.in/icp/assg/sprot.txt https://iws60.iiita.ac.in/icp/assg/nasdaq.txt SwissProt: The file is a data base of proteins. Records are stored sequentially. Some fields might be missing in individuals records. Content of the field is preceeded by a two letter code that identifies the name of the field. A record begins with the field 'ID' and ends with '//'. Eg. ID 104K_SHEAN Reviewed; 893 AA. AC Q4U9M9; DT 01-APR-1990, integrated into UniProtKB/Swiss-Prot. DT 01-APR-1990, sequence version 1. DT 24-JUL-2007, entry version 37. DE 104 kDa microneme/rhoptry antigen precursor (p104). GN OrderedLocusNames=TP04_0437; OS Theileria parva. SQ SEQUENCE 893 AA; 101921 MW; 2F67CEB3B02E7AC1 CRC64; MKFLVLLFNI LCLFPILGAD ELVMSPIPTT DVQPKVTFDI NSEVSSGPLY LNPVEMAGVK YLQLQRQPGV QVHKVVEGDI VIWENEEMPL YTCAIVTQNE VPYMAYVELL EDPDLIFFLK EGDQWAPIPE DQYLARLQQL RQQIHTESFF SLNLSFQHEN YKYEMVSSFQ HSIKMVVFTP KNGHICKMVY DKNIRIFKAL YNEYVTSVIG FFRGLKLLLL NIFVIDDRGM IGNKYFQLLD DKYAPISVQG YVATIPKLKD FAEPYHPIIL DISDIDYVNF YLGDATYHDP GFKIVPKTPQ CITKVVDGNE VIYESSNPSV ECVYKVTYYD KKNESMLRLD LNHSPPSYTS YYAKREGVWV TSTYIDLEEK IEELQDHRST ELDVMFMSDK DLNVVPLTNG NLEYFMVTPK PHRDIIIVFD GSEVLWYYEG LENHLVCTWI YVTEGAPRLV HLRVKDRIPQ NTDIYMVKFG EYWVRISKTQ YTQEIKKLIK KSKKKLPSIE EEDSDKHGGP PKGPEPPTGP GHSSSESKEH EDSKESKEPK EHGSPKETKE GEVTKKPGPA KEHKPSKIPV YTKRPEFPKK SKSPKRPESP KSPKRPVSPQ RPVSPKSPKR PESLDIPKSP KRPESPKSPK RPVSPQRPVS PRRPESPKSP KSPKSPKSPK VPFDPKFKEK LYDSYLDKAA KTKETVTLPP VLPTDESFTH TPIGEPTAEQ PDDIEPIEES VFIKETGILT EEVKTEDIHS ETGEPEEPKR PDSPTKHSPK PTGTHPSMPK KRRRSDGLAL STTDLESEAG RILRDPTGKI VTMKRSKSFD DLTTVREKEH MGAEIRKIVV DDDGTEADDE DTHPSKEKHL STVRRRRPRP KKSSKSSKPR KPDSAFVPSI IFIFLVSLIV GIL // The above record contains the fields ID, AC, DT, DE, GN, OS and SQ. The field SQ contains sequence of the protein and does not have leading 'SQ' for the lines containing the actual sequence. The sequence of this protein (ID=104K_SHEAN) and the record are terminated by '//'. Nasdaq: Each line is a record and fields are seperated by commas. There are no missing fields. The first line gives names of various indices. Each subsequent line is the corresponding index on various days. The first field, for example, is the 'Date'. 1. Print the IDs of all the proteins in sprot.txt 2. Print the scientific names of all the organisms whose proteins have records. The output must be in sorted order. (Hint: You need to process the field OS and discard the information on strains. Use shell command to get an idea as in, "grep ^OS sprot.txt | sort | uniq".) 3. Find the date on which the difference between the N100 and Financial100 is maximum. Level 3 ------- 1. Print the IDs of all the proteins and the number of distinct amino acids in their sequences. (Each amino acid is represented by a single alphabet.) 2. Given the ID of the protein, print the number of times each amino acid occurs in the sequence. 3. Find the Nasdaq index that continued to grow for the longest time at a stretch. B.Tech. (I) - ICP-132 (2009) Assignment 8 Level 0 ------- Implement all the examples for exception handling given in Balaguruswamy. Level 1 ------- 1. Given the following class, write a program to construct and use class 'line' with method to find distance. Class line should also find the slope, but the slope should not be accessible to user (ie, should not be public)! You can have your own data members and methods under private, protected and other placed as indicated below, but the public members cannot be increased. class line { private: protected: public: int x; int y; int dist() { } }; 2. Conisder the class 'movie' given below as a base class. Use it to construct two derived classes, 'bollywood' and 'hollywood'. Each has a data member 'certificate'. The values that can be accepted for certificate are 'U', 'U/A' and 'A' for bollywood and 'G', 'PG' and 'PG-13' for hollywood. User should be able to assign any of the above ceritificate to a movie but nothing else. If no valid certificate is available 'N/A' is to be the default value. Write a program that uses such classes. 3. Create the base class 'country' and derived classes 'monarchy' and 'democracy' with the following restrictions: class country { public: int population; int area; int no_of_states; }; class monarchy { public: string king; string queen; string minister; }; class democracy { public: string president; string vice_president; string prime_minister; }; Show how to use these to access all the members of the derived classes. Level 2 ------- 1. Create a derived class ind_mov that uses both democracy class and bollywood class. Show how to use it to get various information about India and its movies. 2. Create a derived class 'y_intercept' using class 'line' as a base class and the slope available in the 'line'. Given the two points, create a public method 'c' that returns the y-intercept. 3. Create two classes 'read' and 'copy' as shown below. Use them to open a given file name and copy it to another file. The file names are given by the user. Class 'copy' must inherit 'read' to complete its task. Is it necessary that 'read' class needs to be inherited to do the job even if it is mandatory to use 'read'? class read { private: protected: public: string ip_file; void read_file(string fname) { } }; class copy : { private: protected: public: string ip_file; void copy_file(string fname) { } }; 4. Create class 'two_lines' using class 'line'. It should have a bool returning method 'if_intersect' that returns true if the two lines intersect and false otherwise. 5. Inheriting the class copy, create a class 'file_class' that can be used to create, append and overwrite files. 6. Create a class 'state' which have list of states in a country along with the information on the state capitol and population. Create a class from this called 'country' that holds the information about states of various countries. B.Tech. (I) - ICP-132 (2009) Assignment 9 Level 0 ------- 9.0.1. Class P has three private members (x, y, z) which are all integers. Write a program that implements the function Opt that will make y=-(x+z) to a constant object of class P. 9.0.2. Set the values of the three coordinates of object of class P using another class as origin. 9.0.3. Using a class P2, extract the values of (x and y) from an object of class P. Level 1 ------- 9.1.1. L1 and L2 are lists of integers with same size. Overload the operator '+' so that list L3=L1+L2 results in a list that is made by adding corresponding elements of the two lists. Eg: Input: L1: 1, 5 L2: 2, 6, 8 Output: L3: 1, 5, 2, 6, 8 9.1.2. Let M1 and M2 be two maps. Overload the operator '+' so that map M3=M1+M2 results in addition of both maps resulting in a map with all the pairs in M1 and M2. You may assume no common keys between M1 and M2. Eg: Input: M1: <"k1", 10>, <"k2", 20> M2: <"k3", 30>, <"k4", 60>, <"k5", 70> Output: M3: <"k1", 10>, <"k2", 20>, <"k3", 30>, <"k4", 60>, <"k5", 70> 9.1.3. Let M1 and M2 be two maps. Overload the operator '+' so that map M3=M1+M2 results in addition of both maps resulting in a map with all the pairs with common keys having values added. Eg: Input: M1: <"k1", 10>, <"k2", 20> M2: <"k1", 30>, <"k4", 60>, <"k5", 70> Output: M3: <"k1", 40>, <"k2", 20>, <"k4", 60>, <"k5", 70> Level 2 ------- 9.2.1. Create a class Matrix which stores a 2-d integers of a matrix with a dimension nxm. Overload operator '+' to add two matrices, each of which is an object of class Matrix. 9.2.2. Overload operator '+' to add a list and a vector to result in a list on the lines given in 9.1.1. 9.2.3. Create a class Matrix which stores a 2-d integers of a matrix with a dimension nxm. Overload operator '*' to multiply two matrices, each of which is an object of class Matrix. B.Tech. (I) - ICP-132 (2009) Assignment 10 Level 0 ------- 1. Let ptr_i be a pointer to an integer 'i'. Show how to change the value of 'i' using the pointer. 2. Print the address of ptr_i and i as given in the above example. 3. Print the address, value stored and the value stored at the pointed address for ptr_i using three different functions. Level 1 ------- 1. Let x and y be two integers with values 10 and 20. Write a function 'swap' that takes the addess of these two integers and swaps their values. 2. Let ptr_x and ptr_y be the pointers to x and y as discussed above. Write a function ptr_swap that exchanges the address of these two pointers using references. 3. Let ptr_x and ptr_y be the pointers to x and y as discussed above. Write a function ptr_swap that exchanges the address of these two pointers using pointers. Level 2 ------- 1. Let A1 be a 1-dimensional array of size 10. Show how to store the first ten odd numbers in the array. Print these values with and without using their indices! 2. In the above problem A1 is itself a pointer. Let B1 be a pointer that is A1+5. Can one access an element B1-2? Show if it is allowed and find the values of *(A1+2) and *(B1-1). 3. Let A2[4][4] be a two-dimensional matrix such that A[i][j]=(10*i)+j. What values will be printed? Also write a function mat_add that adds two matrices of order 4x5. (See "Pointer Arithmetic and Multiple Indirection" at http://www.technoplaza.net/programming/lesson9.php) Code: #include using namespace std; int main() { int A2[4][4]; for (int i=0; i<4; i++) { for (int j=0; j<4; j++) { A2[i][j]=10*i+j; } } cout << **(A2+1) << endl; cout << *(*(A2+2)+3) << endl; return 0; } 4. Let A3[4][4][4] be a two-dimensional matrix such that A[i][j]=(10*i)+j. What values will be printed? (3-D arrays are pointer-of-pointers-of-pointers.) Code: #include using namespace std; int main() { int A3[4][4][4]; for (int i=0; i<4; i++) { for (int j=0; j<4; j++) { for (int k=0; k<4; k++) { A3[i][j][k]=100*i+10*j+k; } } } cout << ***(A3+1) << endl; cout << **(*(A3+2)+3) << endl; cout << *(*(*(A3+2)+3)+1) << endl; return 0; } 5. Let 'add' and 'mult' be two functions with same type of arguements. Demonstrate usage of switch and pointers to function by executing add to do something if a bool variable is true and mult if it is false. 6. Let 'add' and 'mult' be two functions with same type of arguements. Demonstrate usage of switch and pointers to function by executing add to do something if a there are even number of 1s in the binary representation of an integer 'n' given as input and mult otherwise. (For instance, if 5 is stored as an integer and if integer has 4 bytes, then the binary representation could be 00000000 00000000 00000000 00000101. Here there are 2 ones and the rest 16 are zeros. 7. Demonstrate adding of two objects through overloading '+' using their pointers. 8. Connect an object of class P defined below to another object of the same class. Print the content of the second object (ob2) using the address stored in the first object (ob1). To do this, you may use the following code by completing the line with cout. Similarly demonstrate the same for a dynamically created object. Code: #include using namespace std; class C { public: int x; C *ptr_C; }; int main() { C *ob_ptr; C ob1; C ob2; ob2.x=10; ob1.ptr_C=&ob2; ob_ptr=new C; // create an object of type C (*ob_ptr).x=20; // set value of x as 20 ob2.ptr_C=ob_ptr; // store the address of this object cout ; cout ; return 0; } 9. Write a program to add n objects of class C as above and connect them in the similar way. Print all the values of the objects using their pointers stored in another objects.