Thursday, December 8, 2011

I NEED THE CODE OF FEW PROGRAMS IN C++......PLZZZZZ....HELP ME GUYS...PLZZZ....I'LL BE VERY THANKFUL TO U GUYS?

QUES 1 .Create 2 classes OM and DB which store the value of distance. DM store distances in meters and cm and DB in feet and inches. Write a program that can read values for the


class objects and add 1 object OM with another object of DB. .





Use a friend function to carry out the addition operation the object that stores the results


may be a DM object or a DB object, depending upon the units in which the results are


require. The display should be in the format of feet and inches or meters and cms


depending on the object on display





QUES 2. A book shop maintains the inventory of books that are being sold at the shop the list includes details such as author, title and publisher and stock position. Whenever a customer wants the book, the sales person inputs the title and author and the system


search the list and display whether it is available ornot. If it is not, a appropriate message is displayed, if it is, then the system displays the book details and requests for the number of copies require. If the requested are available, the total cost of the required copies is displayed: otherwise the message" Required copies not in stock"is displayed. Design a system using a class called books with suitable member functions and constructors. Use new operator in constructor to allocate memory space require.





QUES 3. Define a class string that could work as a userdefined string type include constructors that will enable us to create an .un-initialized string


String s1; :/ string with length 0


And also to initialize an object with string constant at the time of creation like


String s2("well done"); .


Include a function that adds two strings to make a third string.





QUES 4. Create a base class called shape use this class to store two double type values that could be used to compute the area of fig. Derive the specific class called TRIANGLE and RECTANGLE from the data shape. Add to base class, a member function get - data ( ) to initialize base class data members and another member and another member function


display 鈥?area( ) to compute and display the area of the fig.. Make display 鈥?area ( ) as a


virtual function and redefine function in the derived classes to suit their requirements,


Using these 3 classes design a program that will accept dimension of RECTANGLE or


TRIANGLE interactivity and display the area.


Remember the 2 values given as input will be treated as length of 2 sides in the case of


rectangle and as base and height in the case of triangles and used as follows:


Area of rectangle = x*y


Area of triangle = 1/2 *x*y





QUES 5. WRITE AN INTERACTIVE OPERATOR OVERLOAD PROGRAM TO MANIPULATE MATRICES.OVERLOAD OPERATORS SUCH AS %26lt;%26lt;,%26gt;%26gt; AND + FOR OPERATIONS ON A SINGLE DIMENSION ARRAY.





QUES 6. Assume that a bank maintains two kinds of accounts for customers, one called savings account and the other as current account. The savings account provides compound interest and withdrawal facilities but no cheque book facility. The current account provides cheque book facility but no interest. Current account holders should also maintain a minimum balance and if the balance falls below this level, a service charge is imposed.


Create a class ACCOUNT that stores customer name, account number and type of account. From this derive the class CUR_ACCT and SAV_ACCT to make them more specific to their requirements.WRITE A FUNCTION TO DEPOSIT, WITHDRAW AND QUERY BALANCES.





QUES 7. write a program to manipulate N student objects.overload a subscript operator for bounds check while accessing ith student object when i%26gt;=N.





ques 8. design a single link list class having functionality to add nodes,traverse and print nodes.write a program to perform these task.





ques 9. WRITE A PROG TO COMPUTERIZE THE UNIVERSITY LIBRARY.THE LIBRARY HAS TWO TYPES OF MEMBERS:STUDENT,STAFF.THE STUDENT CAN BORROW 3 BOOKS AND THE STAFF CAN TAKE 10 BOOKS ONLY.THE DUE DATE IS 7 DAYS AND 30 DAYS FOR STAFF.IF THE BOOKS IS NOT RETURNED BY DUE DATE FINE IS PUT FOR EACH DAY.STAFF HAS NO FINE.


DESIGN COMPLETE PROG USING INHERITANCE, VIRTUAL FUNCTION,ABSTRACT CLASSES.WRITE A FUNCTION TO WITHDRAW BOOKS FROM LIBRARY.





QUES 10. WRITE A PROGRAM TO OVERLOAD 'NEW' AND 'DELETE' OPERATORS SO THAT THE MEMORY RESOURCES ARE HANDLED IN BETTER WAY.





QUES 11. WRITE A PROG TO OVERLOAD THE RELATIONAL OPERATOR %26lt;,%26gt;,== AND != TO WORK ON STRING TYPE OF OBJECT.





QUES 12. WRITE A PRO USING CLASSES TO CREATE A SINGLE LINK LIST.THE SHOULD HAVE CAPABILITY TO ADD, DELETE AND PRINT THE NODES.





QUES 13. WRITE A PROGRAM USING CLASS TEMPLATE TO SEARCH AN ELEMENT IN AN ARRAY USING BINARY SEARCH METHOD.ASSUME THAT THE ARRAY IS ALREADY SORTED.





QUES 14. CONSIDER AN EXAMPLE OF DECLEARING THE EXAMINATION RESULT.DESIGN 3 CLASS: STUDENT,EXAM AND RESULT.THE STUDENT CLASS HAS DATA MEMBERS OF STUDENT INFORMATION.CREATE A CLASS EXAM BY INHERITING STUDENT CLASS.DERIVE THE RESULT CLASS FROM EXAM CLASS AND ADD YOUR OWN DATA AND|||You're asking for a lot, too much actually. Many of us here could code good solutions to every one of these problems, but why would we? If you're taking a course, and you have any interest in it at all, work these out yourself. There is some interesting stuff here, and some fun to be had for someone who cares about C++ and OO programming. If you don't care, perhaps you should drop the class.





Admonishments aside, I'll give you an answer to the one that was interesting to me. I hope it will motivate you to get busy on the others.





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using namespace std;





template%26lt;typename T, size_t Size=1%26gt; struct Array {


聽 聽 T array[Size];


};





template%26lt;typename T, size_t Size%26gt;


size_t len(const Array%26lt;T,Size%26gt;%26amp;) {


聽 聽 return Size;


}





template %26lt;typename T, size_t Size%26gt;


int binarySearch(const Array%26lt;T,Size%26gt;%26amp;, size_t, size_t, const T%26amp;);


template %26lt;typename T, size_t Size%26gt;


void print(const Array%26lt;T,Size%26gt;%26amp;a, const string%26amp;);





const string zero("zero");


const string one("one");


const string two("two");


const string three("three");


const string four("four");





int main(int argc, char *argv[]){


聽 聽 Array%26lt;int,5%26gt; a1;


聽 聽 Array%26lt;string,4%26gt; a2;


聽 聽 size_t a1Len = len(a1);


聽 聽 size_t a2Len = len(a2);





聽 聽 // initialize


聽 聽 for (size_t i = 0; i %26lt; a1Len; i++) {


聽 聽 聽 聽 a1.array[i] = (i+1)*10;


聽 聽 }


聽 聽 a2.array[0] = one;


聽 聽 a2.array[1] = three;


聽 聽 a2.array[2] = two;


聽 聽 a2.array[3] = zero;





聽 聽 // print


聽 聽 print(a1,"a1");


聽 聽 print(a2,"a2");





聽 聽 // search


聽 聽 int x = binarySearch(a1,0,a1Len-1,30);


聽 聽 cout %26lt;%26lt; "search for 30 in a1 returned: " %26lt;%26lt; x %26lt;%26lt; endl;


聽 聽 x = binarySearch(a1,0,a1Len-1,99);


聽 聽 cout %26lt;%26lt; "search for 99 in a1 returned: " %26lt;%26lt; x %26lt;%26lt; endl;





聽 聽 x = binarySearch(a2,0,a2Len-1,one);


聽 聽 cout %26lt;%26lt; "search for \"" %26lt;%26lt; one;


聽 聽 cout %26lt;%26lt; "\" in a2 returned: " %26lt;%26lt; x %26lt;%26lt; endl;


聽 聽 x = binarySearch(a2,0,a2Len-1,three);


聽 聽 cout %26lt;%26lt; "search for \"" %26lt;%26lt; three;


聽 聽 cout %26lt;%26lt; "\" in a2 returned: " %26lt;%26lt; x %26lt;%26lt; endl;


聽 聽 x = binarySearch(a2,0,a2Len-1,zero);


聽 聽 cout %26lt;%26lt; "search for \"" %26lt;%26lt; zero;


聽 聽 cout %26lt;%26lt; "\" in a2 returned: " %26lt;%26lt; x %26lt;%26lt; endl;


聽 聽 x = binarySearch(a2,0,a2Len-1,four);


聽 聽 cout %26lt;%26lt; "search for \"" %26lt;%26lt; four;


聽 聽 cout %26lt;%26lt; "\" in a2 returned: " %26lt;%26lt; x %26lt;%26lt; endl;





聽 聽 return 0;


}





template %26lt;typename T, size_t Size%26gt;


void print(const Array%26lt;T,Size%26gt;%26amp;a, const string %26amp;s) {


聽 聽 cout %26lt;%26lt; s %26lt;%26lt; ":" %26lt;%26lt; endl;


聽 聽 for (size_t i = 0; i %26lt; len(a); i++) {


聽 聽 聽 聽 cout %26lt;%26lt; "\t" %26lt;%26lt; a.array[i] %26lt;%26lt; endl;


聽 聽 }


聽 聽 cout %26lt;%26lt; endl;


}





template %26lt;typename T, size_t Size%26gt;


int binarySearch(const Array%26lt;T,Size%26gt;%26amp;a, size_t first, size_t last, const T %26amp;x) {


聽 聽 if ((x %26lt; a.array[first]) || (x %26gt; a.array[last])) return -1;


聽 聽 if (a.array[first] == x) return first;


聽 聽 else if (a.array[last] == x) return last;


聽 聽 int mid = (first+last)/2;


聽 聽 if (x %26gt; a.array[mid]) return binarySearch(a,mid+1,last,x);


聽 聽 else return binarySearch(a,first,mid,x);


}





#if 0





Program output:





a1:


聽 聽 聽 聽 聽 聽 聽 聽 10


聽 聽 聽 聽 聽 聽 聽 聽 20


聽 聽 聽 聽 聽 聽 聽 聽 30


聽 聽 聽 聽 聽 聽 聽 聽 40


聽 聽 聽 聽 聽 聽 聽 聽 50





a2:


聽 聽 聽 聽 聽 聽 聽 聽 one


聽 聽 聽 聽 聽 聽 聽 聽 three


聽 聽 聽 聽 聽 聽 聽 聽 two


聽 聽 聽 聽 聽 聽 聽 聽 zero





search for 30 in a1 returned: 2


search for 99 in a1 returned: -1


search for "one" in a2 returned: 0


search for "three" in a2 returned: 1


search for "zero" in a2 returned: 3


search for "four" in a2 returned: -1





#endif|||R u serious?????????????????????|||These are very simple homework problems - you should try a nd answer tthem yourself first before asking for help - that way you may learn a little about programming etc

No comments:

Post a Comment