none
C/Cpp Programming Puzzles RRS feed

  • Question

  • Hi Every body

                              Here we will discuss c/cpp puzels,programs and quries daily

        

    Thursday, March 22, 2007 11:10 AM

Answers

  • Suggested Books:

    Most of the experienced programmers out here strongly feel that one should avoid Kanetkar, Balaguruswamy etc. While learning C or C++ it is important that one does not take a false first step.


    The books we STRONGLY DO NOT RECOMMEND

    1.) Books by Kanetkar
    2.) Books by Balaguruswamy

    They are very popular in India and hence we have mentioned them so strongly here.

    Programming Languages:
    1. Concepts of Programming Languages - Robert Sebesta


    C++:
    1. The ISO standard on C++. (2003)
    2. The C++ Programming Language, Special Edition - Bjarne Stroustrup
    3. Thinking in C++.
    4. The Design and Evolution of C++ - Bjarne Stroustrup.
    5. Inside the C++ Object Model - Stanley Lippman
    6. C++ FAQs 2e.
    7. C++ FAQs Lite (Google it)
    8. Effective C++ - 55 Specific Ways to Improve Your Programs and Designs 3e.

    Thursday, March 22, 2007 11:12 AM

  • Ans - These two concern the polymorphic implementation and are not part of the C++ language. Consider the following piece of code

    void someFunc(base* b) {
    b->overridenFunc();
    }

    How do we know what would 'b' point to at run-time, and which overridenFunc() to be called? It can either point to a base class or to a derived class object. How should compiler produce the code so that it executes properly at the run-time?

    To overcome it a language implementation uses the concept of database indirection. A pointer variable (virtual pointer -- vptr) to a data table (virtual table -- vtbl) is internally added to the 'polymorphic object' (an object containing virtual function, or having virtual inheritance). This data contains at least the addresses of recently overriding functions. Overriding functions replace the old functions of previous derivation/base.

    typedef struct vtbl {
    type_info _t; //type_info of class for RTTI
    int *addr_array[FIXED_SIZE];
    };

    vtbl *vptr;

    Say, our vtbl contains (not including the type_info):

    &baseFuncNotOverride(), &OtherOverridenFunc(), &overridenFunc(), ...

    So we can write:

    void someFunc(base* b) {
    b->overridenFunc();
    }

    as

    void someFunc(base* b) {
    //considering that overridenFunc() is a third virtual func
    b->vptr[2](b); // b is passed as implicit 'this'
    }

    Wallah... Problem solved. This works because even if the next derivation overrides the function its place in the table remains constant.
    Thursday, March 22, 2007 11:14 AM

  • Ans - YES, in MI(multiple inheritance) and VI (virtual inheritance) for many implementations like GCC, and Microsoft. For cfront, GCC please refer to "Inside the C++ Object Model" by Stanley Lippman. Mr. Lippman was a member of the team which wrote the first C++ implementation (cfront), under the guidance of the man Bjarne himself. For Microsoft PATENT please refer to:

    http://freepatentsonline.com/5410705.html (without images)

    If someone has doubts about Microsoft compiler, here is the patent example cited:

    class C1:A1,A3{
    int mc1;
    int mc2;
    int fc10();
    virtual int fa11();
    virtual int fa32();
    virtual int fc11();
    };

    And there are two virtual tables shown. If, you think I am crazy please refer to the patented document here:

    http://www.esnips.com/web/MyComputerPapers (with images)

    I guess, the patents don't lie. If you still beg to differ shout at Microsoft for not sticking to their patents.

    One thing to note, virtual tables are implementation constructs and are not related to the C++ standard, so, you can have a compiler that create one or even no virtual tables (if you want to).

    Thursday, March 22, 2007 11:15 AM

  • Ans - Virtual mechanism acts on 'complete objects'. An object is complete 'after' the constructor has finished executing. So, it is illegal to make constructors virtual. Destructors can be virtual because by the time you apply them object has been constructed completely
    Thursday, March 22, 2007 11:17 AM


  • Ans -

    C-Style Casts

    class A {};
    class B {};
    A *a=new A;
    B *b=(B*)a; /*This is C style forced cast, it can result in total absurd behaviour, use it only for built in data types.*/

    C-Style casts don't honour const, volatile restrictions and don't know anything about class hierarchies.

    Note: b & a have same memory location in this case.

    Static Casts

    Less dangerous than C-style forced cast and can be use to convert base class pointer to derived class pointer. Since, it is done on compile time, the dynamic type of base class pointer is not known, hence can result into disaster.

    class A {};
    class B:public A{};
    A *a=new A;
    B *b=static_cast<B*>(a); /*this compiles well but will have run time undefined behaviour because 'a' actually points to A type of object, not any of its derived.*/

    had it been like

    A *a=new B;
    B *b=static_cast<B*>(a); /*This is safe now, try introducing a data member in A and then see the difference in 'a' and 'b'*/

    Static casts honour const, and volatile restrictions and know about class hierarchies.

    Dynamic Casts

    It is type safe. It is done at runtime so that correct type can be determined. It returns NULL (pointer) or throws exception (reference) if conversion is unsuccessful.

    NOTE: For dynamic_cast base class should have at least one virtual member function (i.e., should be polymorphic), and proper RTTI flags should be used.

    Example:

    #include <iostream>
    #include <exception>
    using namespace std;

    class A { virtual dummy() {} };
    class B: public A { int a; };

    int main () {
    try {
    A * pba = new B;
    A * paa = new A;
    B * pb;

    pb = dynamic_cast<B*>(pba);
    if (pb==0) cout << "Null pointer on first type-cast" << endl;

    pb = dynamic_cast<B*>(paa);
    if (pb==0) cout << "Null pointer on second type-cast" << endl;

    } catch (exception& e) {cout << "Exception: " << e.what();}
    return 0;
    }
    Thursday, March 22, 2007 11:22 AM


  • Ans- Here is what Bjarne says:

    To ensure that the addresses of two different objects will be different. For the same reason, "new" always returns pointers to distinct objects. Consider:
    class Empty { };

    void f()
    {
    Empty a, b;
    if (&a == &b) cout << "impossible: report error to compiler supplier";

    Empty* p1 = new Empty;
    Empty* p2 = new Empty;
    if (p1 == p2) cout << "impossible: report error to compiler supplier";
    }

    There is an interesting rule that says that an empty base class need not be represented by a separate byte:
    struct X : Empty {
    int a;
    // ...
    };

    void f(X* p)
    {
    void* p1 = p;
    void* p2 = &p->a;
    if (p1 == p2) cout << "nice: good optimizer";
    }

    This optimization is safe and can be most useful. It allows a programmer to use empty classes to represent very simple concepts without overhead. Some current compilers provide this "empty base class optimization".

    Courtesy: http://www.research.att.com/~bs/bs_faq2.html#sizeof-empty

    Now, what should be the size of an empty class? It depends on how the implementation decides to support the above reasoning.
    Thursday, March 22, 2007 11:25 AM
  • Ans- The ‘virtual’ mechanism works on a logically complete (completely constructed) object. We know that we use constructors to logically initialize our objects. In other words, the object is not completely constructed until the constructor has finished executing. Thus, we can’t have virtual constructors.

    There is a misconception that by then virtual table is incomplete so we can’t have virtual constructors. Just before the constructor starts executing the virtual table is properly constructed and the ‘this’ pointer passed to the constructors. Moreover, virtual table mechanism is implementation depended, and finds no place in the C++ standard. And hence, to argue over this issue using the virtual table concept is illogical.

    Now, as the constructor finishes executing any other function can be virtual. Destructor is no exception to this rule as it is a function. Virtual destructors are required in case we use a base class pointer to refer to a derived class object, use it, and then delete it. If we have virtual destructor, using ‘delete’, a chain of destructors is called starting from the derived to the base. But, had there been no ‘virtual’ in destructor only the base class destructor is called (and not the derived). This (may) generate inconsistencies in the program.

    References:
    1. Inside the C++ Object Model – Stanley Lippman (implemented C++ with Bjarne).
    2. http://www.research.att.com/~bs/bs_faq2.html#virtual-ctor – By Bjarne himself.
    Thursday, March 22, 2007 11:28 AM
  • Can any one Send me a Code to reboot a computer ?...
    Thursday, March 22, 2007 11:31 AM
  • code...................
    void *p()
    {
    p=0xFFFF0000;
    }
    main()
    {
    *p();
    }
    i think this might work........juz try not sure.........
    Thursday, March 22, 2007 12:20 PM
  • Thanks man its very useful in quiz
    Thursday, March 22, 2007 12:46 PM
  • Using Linked Lists
    First of all you will need to create a linked list to store large integers. The technique to represent large nos. using linked lists can be found in any good book of data structures. You may refer Tannenbaum or Kruise.

    Then operations like addition,, subtraction, etc. have to be defined explicitly by you.... and there you go, now you can perform any arithematic operations on large integers.
    Thursday, March 22, 2007 1:04 PM
  • solved linklist .......
    class list
    {
    struct node
    {
    int data;
    node *next;
    }*q;
    public:
    addnode(int x)
    {
    node *q=p;
    if(q==null)
    {
    q=new node;
    q->data=x;
    q->next=null;
    }
    else
    {
    while(q->next!=null)q=q->next;
    r=new node;
    r->data=x;
    r->next=null;
    q->next=r;
    }
    }
    shownodes()
    {
    node *q=p;
    while(q!=null)
    {
    cout<<q->data<<endl;
    q=q->next;
    }
    }
    };
    Thursday, March 22, 2007 1:11 PM
  • Why do you want to create link list in C++. Its already there in it. Use std::list and get yourself some rest.
    Thursday, March 22, 2007 1:29 PM

  • I want to make a programme of GCD by not useing function recall. Tell Me the Solution. Thanks.
    Thursday, March 22, 2007 1:32 PM
  • GCD in C++
    #include <iostream.h>

    int GCD (int, int);
    void main()
    {
    int a,b;
    cout<<"Enter Two Numbers: ";
    cin>>a>>b;
    cout>>"GCD = ">> GCD(a,b));

    }

    int GCD(int a, int b)
    {
    int i;
    for(i=(a<b?a:b); i>=1; i--)
    {
    if (a%i==0 && b%i==0) return i;
    }
    }
    Thursday, March 22, 2007 1:45 PM

  • Let x,y,z be 3 integers . We have to find the greatest of 3 integers, without using relational and conditional operator?????
    Friday, March 23, 2007 6:35 AM

  • cn anybody tell me d practical applications of linked list.....
    Friday, March 23, 2007 6:37 AM
  • max(a,b,c)=( ( a+b+2c+ abs(a-b) ) + ( abs ( a+b-2c+ abs(a-b) ) ) )/4
    Friday, March 23, 2007 12:05 PM

  • Faced a google interview...u r given an array of n integers...ur job is to find maximum and secodn maximum element in N+logN comparisons.
    Friday, March 23, 2007 12:14 PM

  • You have an array. For eg [23,12,45,23,9,23,45]
    Now you have to print the elements in the order of decreasing frequency, and the same no of times as it is coming in the imput aray.
    so the output for this eg would me [23,23,23,45,45,12,9].
    if frequency of two elements is equal, they should come in the same order as they are coming in the input array.

    Can u solve it ? Ask me if you dont understand the question.
    Friday, March 23, 2007 12:15 PM

  • great site for placement preperation..
    http://www.thecareerplus.com/?page=resources&cat=10
    Saturday, March 24, 2007 10:19 AM

  • Tell me on which of the following maximum operations can not be performed by using Abstract Data Type?

    1. Linked List 2. Binary Tree 3. Stack 4. Queue 5. Hash Table
    6. Array
    Saturday, March 24, 2007 10:21 AM
  • Can sum1 please give me d code for reversing a singly linked list!
    Saturday, March 24, 2007 10:22 AM

  • This is a mail i got ....it had compilations from various frnds of mine....some questions and useful tips
    Saturday, March 24, 2007 10:24 AM
  • 16 July 2006 Paper -


    The test was on Analytical(easy), Quantitative(Easy), C(Easy but most on Data Structures).I Attended The test in Development Domain.Merit-Trac Conducted the test. Actually it was for both Testing & Devp Posn. Testing I dont Know.These are the quesns that was asked on C.Hope this Will help u a Lot. Waiting for results.Thank U.Bye Bye
    1) Wap to reverse a linked list and sort the same.
    2) Given two integers A & B. Determine how many bits required to convert
    A to B. Write a function int BitSwapReqd(int A, int B);
    3) Write an algorithm to insert a node into sorted linked list.After inserting,
    the list must be sorted.
    4) Without using /,% and * operators. write a function to divide a number by 3.
    itoa() function is available.
    5) Wap to swap two integer pointers.
    6)Write a funcn int round(float x) to round off a floating point num to int.
    7) write an ALP to find sum of First n natural numbers using the following Instructions

    LDA num ; load Accumulator with num
    DCR R ; decrement Register R
    INR R ; increment Register R
    MOV x,y ; move the contents of register y into register x
    JZ label ; jump to label if A=0
    DJNZ label; Decrement & Jump if A <> 0
    you can use B & C registers in addition to A register
    8) prove that a tree is BST.what is height of a tree?
    9) Given A,B & C Boolean polynomials.Prove That (A+BC)=(A+B)(A+C)
    Saturday, March 24, 2007 10:25 AM
  • Candidate experience on Adobe written test:
    ADOBE PATTERN - MAY 2006
    Hello'

    There were four section:
    1. Aptitude: They had fairly simple arithmatic question, questions on geometry and questions like whether information can be deduced from the comments given. It was fairly easy and jst u need to have basic clear.
    2. Analytical: Questions like pattern matching, odd one out were there.
    Be careful while attempting these two sections that u wont be having much time. Before u know the time is over.
    3. Computers: This paper is mostly from the topics u cover in B.Tech.
    there was one question on finite automata,Bit manipultaion(flipping the bits),
    drawing the tree given preorder and inorder traversal, finding the formula for N-ary tree to fine number of external nodes.
    4. C/Java: Here u had to write C programs(Mind u no mutiple questions).There was one question to write program to search a string from bigger string, write a algorithm to compute X^n which is of complextity log n, implement atoi function.(U cannot use any standard function in these.)
    Saturday, March 24, 2007 10:26 AM
  • Adobe placement paper:
    It had 4 sections(2 1/2 hrs)
    1. Analytical Aptitude: 15 mins 15 Qs
    2. Quantitative Aptitude: 30 mins 30 Qs
    3. Engineering Test :13 Qs, 1 hr
    4. C/Java Test 15-20 Qs, 45 mins
    The first 2 are ultra-cool, no probs at all.
    The fun starts with the third one:
    Those thirteen questions are completely based on your problem solving capacity:
    There are questions based on data-structures like
    -height of a tree,
    -finding second largest number in an array
    -questions using finite automata
    - write a pgm to find whether a m/c is little endian or big endian
    - lots on bit-wise manipulation
    i could answer 8 out of 13 qs very well.
    The 4th test on C/Java(i took C): is almost the same as the third one with questions like
    - print a number in hexadecimal format without using sprintf
    - optimise the computations in the recursive "nth fibonacci number" algo without using iteration(fairly simple)
    "Instead of using return(fib(n-2)+fib(n-1)), use init lofib=0,hifib=1, start with n=2,lofib=hifib;hifib=fib;fib=lofib+hifi
    b"
    -given any number say 12, find the next multiple of 8 eg 16 using bit-wise manipulations.
    -exchange the integers in a matrix across the secondary diagonal(or non-major diagonal)
    i tried hard but couldn't get a common formula for all cases.
    and many more. No data structures book can directly help.
    one should have very good capacity to solve problems in a very efficient manners.
    One drawback about the test is that it is very lengthy.
    They could have kept some qs for the interview. Nobody can attempt 28 programs in 1 hr 45 mins
    Saturday, March 24, 2007 10:27 AM

  • 1. A majority element in an array A, of size N is an element that appears more than N/2 times (and hence there is atmost
    one such element)

    Write a function which takes an array and emits the majority element (if it exists), otherwise prints NONE as follows:

    I/P : 3 3 4 2 4 4 2 4 4
    O/P : 4

    I/P : 3 3 4 2 4 4 2 4
    O/P : NONE

    2. How do u find the largest repeating string and the number of times it
    repeats in a given string efficiently offcourse !?

    ex :
    String : "abc fghi bc kl abcd lkm abcdefg"
    Ans : "abcd" count = 2

    3. Here is an interesting sequence..
    1 20 33 400 505 660 777 8000 9009 10100 11121
    What are the next few numbers in the above sequence?
    Sunday, March 25, 2007 2:21 PM

  • how do u detect A LOOP IN LINKED LIST AND ELMINATE IT.
    Sunday, March 25, 2007 2:30 PM

  • 1.we have n elements,out of which atleast 1+(n/2) elements are same.
    Find the element in O(n) time.

    2.We have a set of n elements, divide it in two set A and B,such that.
    SUM(elements in A)=SUM(elements in B). in order of n time.
    Sunday, March 25, 2007 2:34 PM
  • 9:26 am(6 hours ago)

    Write a C program which will print : %d
    i.e, the output will be only " %d " nothing extra....
    And U can't use C++ for this.......
    Try...
    Friday, March 30, 2007 10:36 AM

  • can you print 1 to 100 without using any loops and conditions....please avoid goto ????
    Friday, March 30, 2007 10:43 AM

  • Can any one SWAP two number in just one statement in C ????????
    Friday, March 30, 2007 10:47 AM

  • #include<stdio.h>


    int main(){

    printf("%d\n", sizeof(1==1));

    printf("%f\n", sizeof(1==1));

    printf("%d\n", sizeof('x'=='x'));

    printf("%f\n", sizeof('x'=='x'));

    return(0);

    }

    give the output of the above code...
    Friday, March 30, 2007 10:48 AM

  • how do we select only one number from a multiple digit number???????EX 2345 is given i have store it in other array in descending order without using "while" statement
    Friday, March 30, 2007 10:50 AM
  • 1) Deleting a specific node from the end of a linked list.(the node number from end (n) will be given along with the starting pointer to the linked list(number of nodes in linked list is not given).

    Friday, March 30, 2007 10:52 AM
  • 2)Reducing a string of the form "aaaabbbbeeeccc" to "abec", removing the duplicate occurances without taking an extra storage..
    Friday, March 30, 2007 10:53 AM
  • Write a function in c which accepts 8 or 13 as input. It outputs 8 if 13 was the input and vice versa. And oh I almost forgot no conditional operators please.
    Friday, March 30, 2007 10:55 AM

  • Hello Friends,

    In one interview, They asked me..

    Can you tell us how to do Multiplication of two number without using + or * sign ??

    I know for then we can multiply by 2 by using right shift... then what about odd numbers......

    Friday, March 30, 2007 11:00 AM

  • Write something to tell whether a number is a power of 2 using no conditional statements and no looping.
    Friday, March 30, 2007 11:03 AM

  • main()
    {
    unsigned int y = 12;
    int x = -2;

    if(x>y)
    printf ("x is greater");
    else
    printf ("y is greater");
    return 0;
    }

    Guess the answer for above snippet and try to come up with the explanations.
    Friday, March 30, 2007 11:06 AM

  • can sumbody temme the program for calander of a mont
    Friday, March 30, 2007 11:07 AM
  • 11/17/05

    PLEASE WRITE THE SOLUTION FOR THE FOLLWING PUZZLE!!!!!!!!!!!11

    QUESTION:
    when a particular rubber ball is dropped from a given height, h, (in meters) its impact speed (in meters / second) when it hits the ground is given by the formula . The ball then rebounds to two thirds the height from which it last fell.
    Using this information write, Develop a C program that calculates and displays the impact speed of the three bounces and the rebound height of each bounce.
    Test your program using an initial height of 2.0 meters. Run the program twice and compare the results for dropping the ball on Earth (g = 9.81 m/sec2) and on the Moon (g = 1.67 m/sec2).
    Friday, March 30, 2007 11:10 AM

  • Here is a sample C++ program

    #include <iostream.h>

    class Myclass
    {
    };

    int main()
    {
    Myclass o1;
    cout << sizeof(o1);
    return 0;
    }

    Can anyone explain why the output of the program is '1' and not '0' since the class doesn't contain anything ?
    Friday, March 30, 2007 11:11 AM

  • how can v find the duplicates in the array
    in O(n) time. i.e. in a single traverse
    Friday, March 30, 2007 11:13 AM

  • Diffrence between #define and const ??

    like memory location access and others ?
    Friday, March 30, 2007 11:14 AM
  • main()
    {
    int c=- -2;
    printf("c=%d",c);
    }
    Friday, March 30, 2007 11:16 AM

  • Let's see if anybody can come up with the most minimal code to implement the strcpy function...
    Friday, March 30, 2007 11:19 AM

  • i knw dis prob has already been discussed once but m so sorry..i hv forgot the reason....d problem is..

    float a=0.7;
    if(a<0.7)
    cout<<c;
    else
    cout<<c++;

    why it displays the o/p as c
    Saturday, March 31, 2007 8:07 AM

  • I need an information abt which one is the best C++ compiler to use.
    is it Microsoft Visual C++ v6
    Turbo C++
    or GCC
    I dont know more and have never used any other than these 3.
    I am using the Microsoft Visual C++ right now .. but find that the APIs available with it to use are very much microsoft centered.

    Secondly is it avaialbe free for download if yes den where ?

    for GCC i am sure we need Linux but do we have some application to simulate the linux environment in windows and den run GCC.

    Is there some compiler as Borland C++ compiler ?
    Saturday, March 31, 2007 8:17 AM

  • Can anyone help me in understanding what a static function pointer is ?
    And also its scope.
    Saturday, March 31, 2007 8:18 AM

  • without making the object of class ,not making the function static,without use of friend function .how call u class function in main functoin
    Saturday, March 31, 2007 8:20 AM

  • i want to code a c program which is waiting for a key press.....
    can i proceed wid other execution in the same program till user enters the i/p

    i do it in java using multi threading bt is der ne way to do dis in C
    Saturday, March 31, 2007 8:23 AM

  • what is main fun is is exactly?
    can i call main fun like recursive fun.?
    how exactly it works?
    Saturday, March 31, 2007 8:25 AM

  • i need a coding of draft game or n e other in C language

    Saturday, March 31, 2007 8:26 AM

  • if we are writing a program and starts compilations ...how the different memory allotment is done to the variable and function of code....
    Saturday, March 31, 2007 8:28 AM

  • guys,,,cn u give me a logic to develop a program to calculate da determinent of a square matrix of n x n,,,
    Saturday, March 31, 2007 8:30 AM

  • what happens if continue is used instead of break in the cases of a switch ????................
    Saturday, March 31, 2007 8:31 AM

  • can nybdy tell me da format for using # operator....as far as in my concern it is used in string concatenation(nt sure...)
    Saturday, March 31, 2007 8:31 AM

  • guys someone deleted my post,,,,plz i need help ,,
    i m reposting it,,,

    plz xplain me the output,,,

    main()
    {
    char *ptr="johanesburg";

    printf("ptr"-1);

    }


    i thought it to be ptr-1
    Saturday, March 31, 2007 8:32 AM

  • Between two sequence point one variable cannot change its value twice...
    but how it is going to take the operation like

    main()
    {
    int a=3;
    a= ++a + ++a;

    printf("The value of i is %d");

    }
    Saturday, March 31, 2007 8:33 AM

  • #all the header files r included
    {
    float a;
    .
    .
    .
    a=7/22*(42);
    .
    .
    }
    Saturday, March 31, 2007 8:34 AM

  • I am getting runtime error - seg fault? is this can be done?

    #include<string.h>
    #include<stdio.h>
    #include<malloc.h>
    int main()
    {
    float flt = 10.00100;
    char *str = "str";
    memcpy((void*)str,(void*)&flt,sizeof(flt
    ));
    printf("-%s",str);
    return 0;
    }
    Saturday, March 31, 2007 8:35 AM

  • Is anybody know what is the main advantage and disadvantage( if any ) of copy constructor ?
    Saturday, March 31, 2007 8:35 AM

  • How to read a txt file line by line in c++.
    My problem is i have saved a txt file as follows:-
    1 asd
    2 dsf
    3 dsfsdf
    Now i want to write a program where if i give number 2 output should be "dsf".
    Please help me.
    Saturday, March 31, 2007 8:36 AM

  • can any one please tell me ASCII code of Arrow Key, Lsft,Right,Up,Down
    Saturday, March 31, 2007 8:37 AM

  • THE FOLLOWING FN

    WHILE(FILE)
    {
    FILE.READ((CHAR*)&OBJ,SIZEOF(OBJ);
    PUTDATA();
    } WILL PRINT THE THE LAST OBJECT IN THE FILE FOR TWO TIMES....... WHY THIS IS HAPPENING..... I KNOW THE ALTERNATE WAY FOR PRINTING IT ONLY ONCE... BUT MY QUESTION IS WHY IT IS PRINTING TWICE IN ABOVE TYPE FUNCTION
    Saturday, March 31, 2007 8:38 AM

  • Can anybody give me website link to objective type question for C...??
    Saturday, March 31, 2007 8:39 AM

  • i wrote a program in unix as follows:

    int main()
    {
    while(1)
    {
    printf("hello ");
    sleep (10);
    }
    }
    in unix prompt,i redirected the output to a file
    a.out > hello.txt
    after some time, i killed this process and found that hello.txt was empty.can you explain this.
    Saturday, March 31, 2007 8:40 AM
  • difference between nested class and inheretenceof
    class ????
    Saturday, March 31, 2007 8:41 AM

  • may i define default value for binary operator overloading...
    Saturday, March 31, 2007 8:42 AM

  • what is the difference between fork and vfork....

    why vfork is used....
    Saturday, March 31, 2007 8:43 AM

  • Hello,
    This is not an assignment but rather a programming challenge question. I would like to know the "optimal way" of printing a number in terms of words.

    For instance
    if the integer is 8334 I would have to output it as Eight Thousand three hundred thirty four

    And this is the idea which I wanted to implement.
    Store an array of strings starting from (one-Nineteen as words).
    Store one more array and containing "ones","hundred" "thousand"
    I will check the value of the integer and then compare the indexes and output it....However this method would take a long time to run if the number of test cases are very long......

    I would be glad if someone could provide me with an "optimal solution" to this problem.
    Saturday, March 31, 2007 8:44 AM

  • Plz don't use array or if-else.Bcz,the use of switch statement will be good. First of all put an option that what will be the number of digits of your input number.then depending on that :
    U hav a number of switch cases holding:'0' to '9'
    '11' to '19'
    '10','20',... to '90'
    '100' to '900'.
    I think u can understand.
    Saturday, March 31, 2007 8:45 AM

  • because main is a driver of program how can one driver execute more then one program that why main() van not be overload
    Saturday, March 31, 2007 8:46 AM

  • Hello friends,
    This is a question of class 12th boards.
    Please give answer with explanation.
    ****************************************
    ****************************
    In the following program , if the value of N given by the user is 15, what maximum and minimum values
    the program could possibly display? (2)
    #include<iostream.h>
    #include<stdlib.h>
    void main()
    {
    int N, Guessme;
    randomize();
    cin>>N;
    Guessme=random(N)+10;
    cout<<Guessme<<endl;
    }
    Saturday, March 31, 2007 8:49 AM
  • if we have not defined a copy constructor then the compiler automatically makes a copy constructor or bit-by-bit copy is done??

    i found this in sumita arora(i know it is aa real *** book but i have to follow it fr my cbse curriculum and write watever *** is there in ti in tests )

    class A
    {
    public:
    A(){cout<<"Constructing";};
    ~A(){cout<<"Destructing";};
    };

    .
    .
    .

    void fun(A a);

    .
    .
    .

    int main()
    {
    A a;
    fun(a);
    }

    the o/p was

    destructing

    she was saying the constructor is not used...i instead added a copy constructor and found that the copy constructor was being used as i had expected.

    my question is that cud bitwise copty have taken place and constructor ACTUALLY not called???

    my second question why we always use pass by value in copy constructor???

    the explaination i have thought fr this is based on fact that copy constructor is called in pass by value...that an infinite loop of copy constructors will be called (somethign like recursion...copy constructor calling itself again and again). is this the correct reason or there is sum other reason.
    Saturday, March 31, 2007 8:51 AM

  • what is containership in c++ and nested class
    Saturday, March 31, 2007 8:52 AM

  • that runs on a double click of the mouse !
    Saturday, March 31, 2007 10:44 AM

  • how to sort data in increasing order in a multidimensional array...

    eg: 3 1
    7 6

    0/p: 1 3
    6 7
    Saturday, March 31, 2007 10:46 AM

All replies

  • Suggested Books:

    Most of the experienced programmers out here strongly feel that one should avoid Kanetkar, Balaguruswamy etc. While learning C or C++ it is important that one does not take a false first step.


    The books we STRONGLY DO NOT RECOMMEND

    1.) Books by Kanetkar
    2.) Books by Balaguruswamy

    They are very popular in India and hence we have mentioned them so strongly here.

    Programming Languages:
    1. Concepts of Programming Languages - Robert Sebesta


    C++:
    1. The ISO standard on C++. (2003)
    2. The C++ Programming Language, Special Edition - Bjarne Stroustrup
    3. Thinking in C++.
    4. The Design and Evolution of C++ - Bjarne Stroustrup.
    5. Inside the C++ Object Model - Stanley Lippman
    6. C++ FAQs 2e.
    7. C++ FAQs Lite (Google it)
    8. Effective C++ - 55 Specific Ways to Improve Your Programs and Designs 3e.

    Thursday, March 22, 2007 11:12 AM

  • Ans - These two concern the polymorphic implementation and are not part of the C++ language. Consider the following piece of code

    void someFunc(base* b) {
    b->overridenFunc();
    }

    How do we know what would 'b' point to at run-time, and which overridenFunc() to be called? It can either point to a base class or to a derived class object. How should compiler produce the code so that it executes properly at the run-time?

    To overcome it a language implementation uses the concept of database indirection. A pointer variable (virtual pointer -- vptr) to a data table (virtual table -- vtbl) is internally added to the 'polymorphic object' (an object containing virtual function, or having virtual inheritance). This data contains at least the addresses of recently overriding functions. Overriding functions replace the old functions of previous derivation/base.

    typedef struct vtbl {
    type_info _t; //type_info of class for RTTI
    int *addr_array[FIXED_SIZE];
    };

    vtbl *vptr;

    Say, our vtbl contains (not including the type_info):

    &baseFuncNotOverride(), &OtherOverridenFunc(), &overridenFunc(), ...

    So we can write:

    void someFunc(base* b) {
    b->overridenFunc();
    }

    as

    void someFunc(base* b) {
    //considering that overridenFunc() is a third virtual func
    b->vptr[2](b); // b is passed as implicit 'this'
    }

    Wallah... Problem solved. This works because even if the next derivation overrides the function its place in the table remains constant.
    Thursday, March 22, 2007 11:14 AM

  • Ans - YES, in MI(multiple inheritance) and VI (virtual inheritance) for many implementations like GCC, and Microsoft. For cfront, GCC please refer to "Inside the C++ Object Model" by Stanley Lippman. Mr. Lippman was a member of the team which wrote the first C++ implementation (cfront), under the guidance of the man Bjarne himself. For Microsoft PATENT please refer to:

    http://freepatentsonline.com/5410705.html (without images)

    If someone has doubts about Microsoft compiler, here is the patent example cited:

    class C1:A1,A3{
    int mc1;
    int mc2;
    int fc10();
    virtual int fa11();
    virtual int fa32();
    virtual int fc11();
    };

    And there are two virtual tables shown. If, you think I am crazy please refer to the patented document here:

    http://www.esnips.com/web/MyComputerPapers (with images)

    I guess, the patents don't lie. If you still beg to differ shout at Microsoft for not sticking to their patents.

    One thing to note, virtual tables are implementation constructs and are not related to the C++ standard, so, you can have a compiler that create one or even no virtual tables (if you want to).

    Thursday, March 22, 2007 11:15 AM

  • Ans - Virtual mechanism acts on 'complete objects'. An object is complete 'after' the constructor has finished executing. So, it is illegal to make constructors virtual. Destructors can be virtual because by the time you apply them object has been constructed completely
    Thursday, March 22, 2007 11:17 AM


  • Ans -

    C-Style Casts

    class A {};
    class B {};
    A *a=new A;
    B *b=(B*)a; /*This is C style forced cast, it can result in total absurd behaviour, use it only for built in data types.*/

    C-Style casts don't honour const, volatile restrictions and don't know anything about class hierarchies.

    Note: b & a have same memory location in this case.

    Static Casts

    Less dangerous than C-style forced cast and can be use to convert base class pointer to derived class pointer. Since, it is done on compile time, the dynamic type of base class pointer is not known, hence can result into disaster.

    class A {};
    class B:public A{};
    A *a=new A;
    B *b=static_cast<B*>(a); /*this compiles well but will have run time undefined behaviour because 'a' actually points to A type of object, not any of its derived.*/

    had it been like

    A *a=new B;
    B *b=static_cast<B*>(a); /*This is safe now, try introducing a data member in A and then see the difference in 'a' and 'b'*/

    Static casts honour const, and volatile restrictions and know about class hierarchies.

    Dynamic Casts

    It is type safe. It is done at runtime so that correct type can be determined. It returns NULL (pointer) or throws exception (reference) if conversion is unsuccessful.

    NOTE: For dynamic_cast base class should have at least one virtual member function (i.e., should be polymorphic), and proper RTTI flags should be used.

    Example:

    #include <iostream>
    #include <exception>
    using namespace std;

    class A { virtual dummy() {} };
    class B: public A { int a; };

    int main () {
    try {
    A * pba = new B;
    A * paa = new A;
    B * pb;

    pb = dynamic_cast<B*>(pba);
    if (pb==0) cout << "Null pointer on first type-cast" << endl;

    pb = dynamic_cast<B*>(paa);
    if (pb==0) cout << "Null pointer on second type-cast" << endl;

    } catch (exception& e) {cout << "Exception: " << e.what();}
    return 0;
    }
    Thursday, March 22, 2007 11:22 AM


  • Ans- Here is what Bjarne says:

    To ensure that the addresses of two different objects will be different. For the same reason, "new" always returns pointers to distinct objects. Consider:
    class Empty { };

    void f()
    {
    Empty a, b;
    if (&a == &b) cout << "impossible: report error to compiler supplier";

    Empty* p1 = new Empty;
    Empty* p2 = new Empty;
    if (p1 == p2) cout << "impossible: report error to compiler supplier";
    }

    There is an interesting rule that says that an empty base class need not be represented by a separate byte:
    struct X : Empty {
    int a;
    // ...
    };

    void f(X* p)
    {
    void* p1 = p;
    void* p2 = &p->a;
    if (p1 == p2) cout << "nice: good optimizer";
    }

    This optimization is safe and can be most useful. It allows a programmer to use empty classes to represent very simple concepts without overhead. Some current compilers provide this "empty base class optimization".

    Courtesy: http://www.research.att.com/~bs/bs_faq2.html#sizeof-empty

    Now, what should be the size of an empty class? It depends on how the implementation decides to support the above reasoning.
    Thursday, March 22, 2007 11:25 AM
  • Ans- The ‘virtual’ mechanism works on a logically complete (completely constructed) object. We know that we use constructors to logically initialize our objects. In other words, the object is not completely constructed until the constructor has finished executing. Thus, we can’t have virtual constructors.

    There is a misconception that by then virtual table is incomplete so we can’t have virtual constructors. Just before the constructor starts executing the virtual table is properly constructed and the ‘this’ pointer passed to the constructors. Moreover, virtual table mechanism is implementation depended, and finds no place in the C++ standard. And hence, to argue over this issue using the virtual table concept is illogical.

    Now, as the constructor finishes executing any other function can be virtual. Destructor is no exception to this rule as it is a function. Virtual destructors are required in case we use a base class pointer to refer to a derived class object, use it, and then delete it. If we have virtual destructor, using ‘delete’, a chain of destructors is called starting from the derived to the base. But, had there been no ‘virtual’ in destructor only the base class destructor is called (and not the derived). This (may) generate inconsistencies in the program.

    References:
    1. Inside the C++ Object Model – Stanley Lippman (implemented C++ with Bjarne).
    2. http://www.research.att.com/~bs/bs_faq2.html#virtual-ctor – By Bjarne himself.
    Thursday, March 22, 2007 11:28 AM
  • Can any one Send me a Code to reboot a computer ?...
    Thursday, March 22, 2007 11:31 AM
  • code...................
    void *p()
    {
    p=0xFFFF0000;
    }
    main()
    {
    *p();
    }
    i think this might work........juz try not sure.........
    Thursday, March 22, 2007 12:20 PM
  • Can anyone talk about Linklists in C++... and How can we create a Linklist in C++ using Classes... ok Bye bye
    Thursday, March 22, 2007 12:30 PM
  • Thanks man its very useful in quiz
    Thursday, March 22, 2007 12:46 PM

  • how to add 2 nos. while each no. having size 100 bits.
    Thursday, March 22, 2007 12:58 PM
  • Using Linked Lists
    First of all you will need to create a linked list to store large integers. The technique to represent large nos. using linked lists can be found in any good book of data structures. You may refer Tannenbaum or Kruise.

    Then operations like addition,, subtraction, etc. have to be defined explicitly by you.... and there you go, now you can perform any arithematic operations on large integers.
    Thursday, March 22, 2007 1:04 PM
  • solved linklist .......
    class list
    {
    struct node
    {
    int data;
    node *next;
    }*q;
    public:
    addnode(int x)
    {
    node *q=p;
    if(q==null)
    {
    q=new node;
    q->data=x;
    q->next=null;
    }
    else
    {
    while(q->next!=null)q=q->next;
    r=new node;
    r->data=x;
    r->next=null;
    q->next=r;
    }
    }
    shownodes()
    {
    node *q=p;
    while(q!=null)
    {
    cout<<q->data<<endl;
    q=q->next;
    }
    }
    };
    Thursday, March 22, 2007 1:11 PM
  • create a node containing an item and a next pointer to a node. you can create this within a struct.
    you can then form a linked list by connecting these nodes by the next pointers.

    you can look this up in probably any book on C++ or data structures (or look up the ADT List).
    Thursday, March 22, 2007 1:21 PM
  • Why do you want to create link list in C++. Its already there in it. Use std::list and get yourself some rest.
    Thursday, March 22, 2007 1:29 PM

  • I want to make a programme of GCD by not useing function recall. Tell Me the Solution. Thanks.
    Thursday, March 22, 2007 1:32 PM
  • GCD in C++
    #include <iostream.h>

    int GCD (int, int);
    void main()
    {
    int a,b;
    cout<<"Enter Two Numbers: ";
    cin>>a>>b;
    cout>>"GCD = ">> GCD(a,b));

    }

    int GCD(int a, int b)
    {
    int i;
    for(i=(a<b?a:b); i>=1; i--)
    {
    if (a%i==0 && b%i==0) return i;
    }
    }
    Thursday, March 22, 2007 1:45 PM
  • #include <stdio.h>

    int GCD (int, int);
    void main()
    {
    int a,b;
    printf("Enter Two Numbers: ");
    scanf("%d",&a);
    scanf("%d",&b);
    printf("GCD = %d", GCD(a,b));

    }

    int GCD(int a, int b)
    {
    int i;
    for(i=(a<b?a:b); i>=1; i--)
    {
    if (a%i==0 && b%i==0) return i;
    }
    }
    Thursday, March 22, 2007 1:47 PM
  • in java this is the complete program
    class Gcd
    {
    static void gcd(int num1,int num2)
    {
    int a,b,ans;
    ans=1;
    if(num1>num2)
    {
    a=num1;
    num1=num2;
    num2=a;
    }

    for(b=num1; b>1 ; --b)
    {


    if(num1%b==0 && num2%b==0)
    {
    ans=b;
    break;
    }

    }

    System.out.println("gcd is "+ans);

    }




    public static void main(String arg[])
    {
    gcd(78,12);
    }

    }
    Thursday, March 22, 2007 1:48 PM
  • This is really PATHETIC. I've already started forum for that, and you are just copying its topic blindly. This will take you to nowhere.

    I'M STRONGLY AGAINST THIS FORUM. GOT IT ???
    Thursday, March 22, 2007 5:51 PM

  • Let x,y,z be 3 integers . We have to find the greatest of 3 integers, without using relational and conditional operator?????
    Friday, March 23, 2007 6:35 AM

  • cn anybody tell me d practical applications of linked list.....
    Friday, March 23, 2007 6:37 AM
  • for two numbers ..
    let us take two numbers a=10 and b=20
    temp=a/b; (10/20) =0.5
    if(temp>=1) // condition is false ..
    printf("a is greater ");
    else // condition is true
    printf("b is greater ");
    Friday, March 23, 2007 11:02 AM
  • max(a,b,c)=( ( a+b+2c+ abs(a-b) ) + ( abs ( a+b-2c+ abs(a-b) ) ) )/4
    Friday, March 23, 2007 12:05 PM
  • Applications
    Linked Lists r widely used in polynomial addition.Suppose that u have 2 polynomials with orders 200,9,4 and 300,3,1.If u use arrays for this one it consumes too much memory , but if u use linked lists it takes very less memory.
    Friday, March 23, 2007 12:11 PM
  • When u call any function the compiler is only going to push the current stack pointer and base pointer on the process's stack pointed by stack segment register.

    and after executing the fuction call the return statement unpush the previous stacked data.


    And how exacly does the compiler "push" the Stack pointer? The application stack IS implemented by the compiler itself, because it is the compiler that defines the activation record (what all info needs to be stored and in what format), the calling convention (In what order are arguments passed, whether on stack or on registers etc).
    Friday, March 23, 2007 12:12 PM

  • Faced a google interview...u r given an array of n integers...ur job is to find maximum and secodn maximum element in N+logN comparisons.
    Friday, March 23, 2007 12:14 PM

  • You have an array. For eg [23,12,45,23,9,23,45]
    Now you have to print the elements in the order of decreasing frequency, and the same no of times as it is coming in the imput aray.
    so the output for this eg would me [23,23,23,45,45,12,9].
    if frequency of two elements is equal, they should come in the same order as they are coming in the input array.

    Can u solve it ? Ask me if you dont understand the question.
    Friday, March 23, 2007 12:15 PM
  • use linked list .... traverse the array only once O(n) complexity...... wenever u find a new element u store it as a new element else u increase the count of the no. concerned.... this is type of a counting sort....if u use arrays to store elements nd count then then u can use binary search to find the element.....
    Friday, March 23, 2007 12:55 PM
  • Take a look at this code for GCD.. it uses Euclide's theorem for the gcd and that too in a recursive function.. this is the fastest and simplest way to find the gcd...
    if you dont know about the euclide's theorem let me know ill explain it there...

    // WAP to Implement Euclide's Theorem to find the greatest common Divisor..

    #include<stdio.h>
    #include<conio.h>
    int gcd(int x, int y);

    void main()
    {
    int x, y;
    clrscr();
    printf("Please give the 2 numbers to find GCD between : \n");
    scanf("%d %d",&x,&y);
    if(x>y)
    printf("The GCD is = %d",gcd(x,y));
    else
    printf("The Gcd is = %d",gcd(y,x));
    getch();
    }

    int gcd(int x, int y)
    {
    if(y==0)
    return (x);
    else
    return(gcd(y, x%y));
    }
    Saturday, March 24, 2007 4:44 AM
  •  swathi_y_a74c78 wrote:
    code...................
    void *p()
    {
    p=0xFFFF0000;
    }
    main()
    {
    *p();
    }
    i think this might work........juz try not sure.........

    This is a very dangerous thing to try out... you are trying to address the 0th address of memory location where the bios loads the boot strap loader.. why do you want to even touch it. it might just crash the OS... what do you say.. i fear to try it out.. did someone else tried it out???
    Saturday, March 24, 2007 4:47 AM

  • great site for placement preperation..
    http://www.thecareerplus.com/?page=resources&cat=10
    Saturday, March 24, 2007 10:19 AM

  • Tell me on which of the following maximum operations can not be performed by using Abstract Data Type?

    1. Linked List 2. Binary Tree 3. Stack 4. Queue 5. Hash Table
    6. Array
    Saturday, March 24, 2007 10:21 AM
  • Can sum1 please give me d code for reversing a singly linked list!
    Saturday, March 24, 2007 10:22 AM

  • This is a mail i got ....it had compilations from various frnds of mine....some questions and useful tips
    Saturday, March 24, 2007 10:24 AM
  • 16 July 2006 Paper -


    The test was on Analytical(easy), Quantitative(Easy), C(Easy but most on Data Structures).I Attended The test in Development Domain.Merit-Trac Conducted the test. Actually it was for both Testing & Devp Posn. Testing I dont Know.These are the quesns that was asked on C.Hope this Will help u a Lot. Waiting for results.Thank U.Bye Bye
    1) Wap to reverse a linked list and sort the same.
    2) Given two integers A & B. Determine how many bits required to convert
    A to B. Write a function int BitSwapReqd(int A, int B);
    3) Write an algorithm to insert a node into sorted linked list.After inserting,
    the list must be sorted.
    4) Without using /,% and * operators. write a function to divide a number by 3.
    itoa() function is available.
    5) Wap to swap two integer pointers.
    6)Write a funcn int round(float x) to round off a floating point num to int.
    7) write an ALP to find sum of First n natural numbers using the following Instructions

    LDA num ; load Accumulator with num
    DCR R ; decrement Register R
    INR R ; increment Register R
    MOV x,y ; move the contents of register y into register x
    JZ label ; jump to label if A=0
    DJNZ label; Decrement & Jump if A <> 0
    you can use B & C registers in addition to A register
    8) prove that a tree is BST.what is height of a tree?
    9) Given A,B & C Boolean polynomials.Prove That (A+BC)=(A+B)(A+C)
    Saturday, March 24, 2007 10:25 AM
  • Candidate experience on Adobe written test:
    ADOBE PATTERN - MAY 2006
    Hello'

    There were four section:
    1. Aptitude: They had fairly simple arithmatic question, questions on geometry and questions like whether information can be deduced from the comments given. It was fairly easy and jst u need to have basic clear.
    2. Analytical: Questions like pattern matching, odd one out were there.
    Be careful while attempting these two sections that u wont be having much time. Before u know the time is over.
    3. Computers: This paper is mostly from the topics u cover in B.Tech.
    there was one question on finite automata,Bit manipultaion(flipping the bits),
    drawing the tree given preorder and inorder traversal, finding the formula for N-ary tree to fine number of external nodes.
    4. C/Java: Here u had to write C programs(Mind u no mutiple questions).There was one question to write program to search a string from bigger string, write a algorithm to compute X^n which is of complextity log n, implement atoi function.(U cannot use any standard function in these.)
    Saturday, March 24, 2007 10:26 AM
  • Adobe placement paper:
    It had 4 sections(2 1/2 hrs)
    1. Analytical Aptitude: 15 mins 15 Qs
    2. Quantitative Aptitude: 30 mins 30 Qs
    3. Engineering Test :13 Qs, 1 hr
    4. C/Java Test 15-20 Qs, 45 mins
    The first 2 are ultra-cool, no probs at all.
    The fun starts with the third one:
    Those thirteen questions are completely based on your problem solving capacity:
    There are questions based on data-structures like
    -height of a tree,
    -finding second largest number in an array
    -questions using finite automata
    - write a pgm to find whether a m/c is little endian or big endian
    - lots on bit-wise manipulation
    i could answer 8 out of 13 qs very well.
    The 4th test on C/Java(i took C): is almost the same as the third one with questions like
    - print a number in hexadecimal format without using sprintf
    - optimise the computations in the recursive "nth fibonacci number" algo without using iteration(fairly simple)
    "Instead of using return(fib(n-2)+fib(n-1)), use init lofib=0,hifib=1, start with n=2,lofib=hifib;hifib=fib;fib=lofib+hifi
    b"
    -given any number say 12, find the next multiple of 8 eg 16 using bit-wise manipulations.
    -exchange the integers in a matrix across the secondary diagonal(or non-major diagonal)
    i tried hard but couldn't get a common formula for all cases.
    and many more. No data structures book can directly help.
    one should have very good capacity to solve problems in a very efficient manners.
    One drawback about the test is that it is very lengthy.
    They could have kept some qs for the interview. Nobody can attempt 28 programs in 1 hr 45 mins
    Saturday, March 24, 2007 10:27 AM
  •  V N RAGHAVENDRA _VINNAKOTA_c2a3a wrote:
    Can sum1 please give me d code for reversing a singly linked list!


    I have also posted a code for GCD using Eucliede's theorem but instead of posting in last it got posted in the middle, so you can also have a look at it.. as for the other code that you asked for here it is..

    // This is the prog to reverse the link list..
    #include<stdio.h>
    #include<conio.h>

    struct link_list
    {
        int data;
        struct link_list *next;
    };
    typedef struct link_list link;

    link *read()
    {
        link *first = 0, *nw=0;
        int data;
        printf("Please give the data. To stop give 0 as an entry\n");
        scanf("%d", & data);
        while(data!=0)
        {
            nw = (link *)malloc(sizeof(link));
            nw->data = data;
            nw->next = first;
            first = nw;
            scanf("%d", &data);
        }
        return (first);
    }

    void display(link *p)
    {
        while(p != 0)
        {
            printf("\n%d", p->data);
            p = p->next;
        }
    }

    link *rev(link *first)
    {
        link  *node1=0 , *node2=first, *node3=first->next;
        while(node3 != 0)
        {
            node2->next = node1;
            node1 = node2;
            node2 = node3;
            node3 = node3->next;
        }
        node2->next = node1;
        first = node2;
        return(node2);
    }

    void main()
    {
        link *first=0;

        clrscr();
        first = read();
        display(first);
        first = rev(first);
        printf("\nThe list has been reversed\n");
        display(first);
        getch();
    }
    Saturday, March 24, 2007 11:15 AM

  • 1. A majority element in an array A, of size N is an element that appears more than N/2 times (and hence there is atmost
    one such element)

    Write a function which takes an array and emits the majority element (if it exists), otherwise prints NONE as follows:

    I/P : 3 3 4 2 4 4 2 4 4
    O/P : 4

    I/P : 3 3 4 2 4 4 2 4
    O/P : NONE

    2. How do u find the largest repeating string and the number of times it
    repeats in a given string efficiently offcourse !?

    ex :
    String : "abc fghi bc kl abcd lkm abcdefg"
    Ans : "abcd" count = 2

    3. Here is an interesting sequence..
    1 20 33 400 505 660 777 8000 9009 10100 11121
    What are the next few numbers in the above sequence?
    Sunday, March 25, 2007 2:21 PM

  • how do u detect A LOOP IN LINKED LIST AND ELMINATE IT.
    Sunday, March 25, 2007 2:30 PM

  • can anybody tell me how to find the minimum height of a binary tree

    and how to find 2nd largest number in a array..
    Sunday, March 25, 2007 2:31 PM

  • 1.we have n elements,out of which atleast 1+(n/2) elements are same.
    Find the element in O(n) time.

    2.We have a set of n elements, divide it in two set A and B,such that.
    SUM(elements in A)=SUM(elements in B). in order of n time.
    Sunday, March 25, 2007 2:34 PM
  • 9:26 am(6 hours ago)

    Write a C program which will print : %d
    i.e, the output will be only " %d " nothing extra....
    And U can't use C++ for this.......
    Try...
    Friday, March 30, 2007 10:36 AM

  • can you print 1 to 100 without using any loops and conditions....please avoid goto ????
    Friday, March 30, 2007 10:43 AM

  • Can any one SWAP two number in just one statement in C ????????
    Friday, March 30, 2007 10:47 AM

  • #include<stdio.h>


    int main(){

    printf("%d\n", sizeof(1==1));

    printf("%f\n", sizeof(1==1));

    printf("%d\n", sizeof('x'=='x'));

    printf("%f\n", sizeof('x'=='x'));

    return(0);

    }

    give the output of the above code...
    Friday, March 30, 2007 10:48 AM

  • how do we select only one number from a multiple digit number???????EX 2345 is given i have store it in other array in descending order without using "while" statement
    Friday, March 30, 2007 10:50 AM
  • 1) Deleting a specific node from the end of a linked list.(the node number from end (n) will be given along with the starting pointer to the linked list(number of nodes in linked list is not given).

    Friday, March 30, 2007 10:52 AM
  • 2)Reducing a string of the form "aaaabbbbeeeccc" to "abec", removing the duplicate occurances without taking an extra storage..
    Friday, March 30, 2007 10:53 AM
  • Write a function in c which accepts 8 or 13 as input. It outputs 8 if 13 was the input and vice versa. And oh I almost forgot no conditional operators please.
    Friday, March 30, 2007 10:55 AM

  • Hello Friends,

    In one interview, They asked me..

    Can you tell us how to do Multiplication of two number without using + or * sign ??

    I know for then we can multiply by 2 by using right shift... then what about odd numbers......

    Friday, March 30, 2007 11:00 AM

  • Write something to tell whether a number is a power of 2 using no conditional statements and no looping.
    Friday, March 30, 2007 11:03 AM

  • main()
    {
    unsigned int y = 12;
    int x = -2;

    if(x>y)
    printf ("x is greater");
    else
    printf ("y is greater");
    return 0;
    }

    Guess the answer for above snippet and try to come up with the explanations.
    Friday, March 30, 2007 11:06 AM

  • can sumbody temme the program for calander of a mont
    Friday, March 30, 2007 11:07 AM
  • 11/17/05

    PLEASE WRITE THE SOLUTION FOR THE FOLLWING PUZZLE!!!!!!!!!!!11

    QUESTION:
    when a particular rubber ball is dropped from a given height, h, (in meters) its impact speed (in meters / second) when it hits the ground is given by the formula . The ball then rebounds to two thirds the height from which it last fell.
    Using this information write, Develop a C program that calculates and displays the impact speed of the three bounces and the rebound height of each bounce.
    Test your program using an initial height of 2.0 meters. Run the program twice and compare the results for dropping the ball on Earth (g = 9.81 m/sec2) and on the Moon (g = 1.67 m/sec2).
    Friday, March 30, 2007 11:10 AM

  • Here is a sample C++ program

    #include <iostream.h>

    class Myclass
    {
    };

    int main()
    {
    Myclass o1;
    cout << sizeof(o1);
    return 0;
    }

    Can anyone explain why the output of the program is '1' and not '0' since the class doesn't contain anything ?
    Friday, March 30, 2007 11:11 AM

  • how can v find the duplicates in the array
    in O(n) time. i.e. in a single traverse
    Friday, March 30, 2007 11:13 AM

  • Diffrence between #define and const ??

    like memory location access and others ?
    Friday, March 30, 2007 11:14 AM
  • main()
    {
    int c=- -2;
    printf("c=%d",c);
    }
    Friday, March 30, 2007 11:16 AM

  • Let's see if anybody can come up with the most minimal code to implement the strcpy function...
    Friday, March 30, 2007 11:19 AM

  • i knw dis prob has already been discussed once but m so sorry..i hv forgot the reason....d problem is..

    float a=0.7;
    if(a<0.7)
    cout<<c;
    else
    cout<<c++;

    why it displays the o/p as c
    Saturday, March 31, 2007 8:07 AM

  • I need an information abt which one is the best C++ compiler to use.
    is it Microsoft Visual C++ v6
    Turbo C++
    or GCC
    I dont know more and have never used any other than these 3.
    I am using the Microsoft Visual C++ right now .. but find that the APIs available with it to use are very much microsoft centered.

    Secondly is it avaialbe free for download if yes den where ?

    for GCC i am sure we need Linux but do we have some application to simulate the linux environment in windows and den run GCC.

    Is there some compiler as Borland C++ compiler ?
    Saturday, March 31, 2007 8:17 AM

  • Can anyone help me in understanding what a static function pointer is ?
    And also its scope.
    Saturday, March 31, 2007 8:18 AM

  • without making the object of class ,not making the function static,without use of friend function .how call u class function in main functoin
    Saturday, March 31, 2007 8:20 AM

  • i want to code a c program which is waiting for a key press.....
    can i proceed wid other execution in the same program till user enters the i/p

    i do it in java using multi threading bt is der ne way to do dis in C
    Saturday, March 31, 2007 8:23 AM

  • what is main fun is is exactly?
    can i call main fun like recursive fun.?
    how exactly it works?
    Saturday, March 31, 2007 8:25 AM

  • i need a coding of draft game or n e other in C language

    Saturday, March 31, 2007 8:26 AM

  • if we are writing a program and starts compilations ...how the different memory allotment is done to the variable and function of code....
    Saturday, March 31, 2007 8:28 AM

  • guys,,,cn u give me a logic to develop a program to calculate da determinent of a square matrix of n x n,,,
    Saturday, March 31, 2007 8:30 AM

  • what happens if continue is used instead of break in the cases of a switch ????................
    Saturday, March 31, 2007 8:31 AM

  • can nybdy tell me da format for using # operator....as far as in my concern it is used in string concatenation(nt sure...)
    Saturday, March 31, 2007 8:31 AM

  • guys someone deleted my post,,,,plz i need help ,,
    i m reposting it,,,

    plz xplain me the output,,,

    main()
    {
    char *ptr="johanesburg";

    printf("ptr"-1);

    }


    i thought it to be ptr-1
    Saturday, March 31, 2007 8:32 AM

  • Between two sequence point one variable cannot change its value twice...
    but how it is going to take the operation like

    main()
    {
    int a=3;
    a= ++a + ++a;

    printf("The value of i is %d");

    }
    Saturday, March 31, 2007 8:33 AM

  • #all the header files r included
    {
    float a;
    .
    .
    .
    a=7/22*(42);
    .
    .
    }
    Saturday, March 31, 2007 8:34 AM

  • I am getting runtime error - seg fault? is this can be done?

    #include<string.h>
    #include<stdio.h>
    #include<malloc.h>
    int main()
    {
    float flt = 10.00100;
    char *str = "str";
    memcpy((void*)str,(void*)&flt,sizeof(flt
    ));
    printf("-%s",str);
    return 0;
    }
    Saturday, March 31, 2007 8:35 AM

  • Is anybody know what is the main advantage and disadvantage( if any ) of copy constructor ?
    Saturday, March 31, 2007 8:35 AM

  • How to read a txt file line by line in c++.
    My problem is i have saved a txt file as follows:-
    1 asd
    2 dsf
    3 dsfsdf
    Now i want to write a program where if i give number 2 output should be "dsf".
    Please help me.
    Saturday, March 31, 2007 8:36 AM

  • can any one please tell me ASCII code of Arrow Key, Lsft,Right,Up,Down
    Saturday, March 31, 2007 8:37 AM

  • THE FOLLOWING FN

    WHILE(FILE)
    {
    FILE.READ((CHAR*)&OBJ,SIZEOF(OBJ);
    PUTDATA();
    } WILL PRINT THE THE LAST OBJECT IN THE FILE FOR TWO TIMES....... WHY THIS IS HAPPENING..... I KNOW THE ALTERNATE WAY FOR PRINTING IT ONLY ONCE... BUT MY QUESTION IS WHY IT IS PRINTING TWICE IN ABOVE TYPE FUNCTION
    Saturday, March 31, 2007 8:38 AM

  • Can anybody give me website link to objective type question for C...??
    Saturday, March 31, 2007 8:39 AM

  • i wrote a program in unix as follows:

    int main()
    {
    while(1)
    {
    printf("hello ");
    sleep (10);
    }
    }
    in unix prompt,i redirected the output to a file
    a.out > hello.txt
    after some time, i killed this process and found that hello.txt was empty.can you explain this.
    Saturday, March 31, 2007 8:40 AM
  • difference between nested class and inheretenceof
    class ????
    Saturday, March 31, 2007 8:41 AM

  • may i define default value for binary operator overloading...
    Saturday, March 31, 2007 8:42 AM

  • what is the difference between fork and vfork....

    why vfork is used....
    Saturday, March 31, 2007 8:43 AM

  • Hello,
    This is not an assignment but rather a programming challenge question. I would like to know the "optimal way" of printing a number in terms of words.

    For instance
    if the integer is 8334 I would have to output it as Eight Thousand three hundred thirty four

    And this is the idea which I wanted to implement.
    Store an array of strings starting from (one-Nineteen as words).
    Store one more array and containing "ones","hundred" "thousand"
    I will check the value of the integer and then compare the indexes and output it....However this method would take a long time to run if the number of test cases are very long......

    I would be glad if someone could provide me with an "optimal solution" to this problem.
    Saturday, March 31, 2007 8:44 AM

  • Plz don't use array or if-else.Bcz,the use of switch statement will be good. First of all put an option that what will be the number of digits of your input number.then depending on that :
    U hav a number of switch cases holding:'0' to '9'
    '11' to '19'
    '10','20',... to '90'
    '100' to '900'.
    I think u can understand.
    Saturday, March 31, 2007 8:45 AM

  • because main is a driver of program how can one driver execute more then one program that why main() van not be overload
    Saturday, March 31, 2007 8:46 AM

  • Hello friends,
    This is a question of class 12th boards.
    Please give answer with explanation.
    ****************************************
    ****************************
    In the following program , if the value of N given by the user is 15, what maximum and minimum values
    the program could possibly display? (2)
    #include<iostream.h>
    #include<stdlib.h>
    void main()
    {
    int N, Guessme;
    randomize();
    cin>>N;
    Guessme=random(N)+10;
    cout<<Guessme<<endl;
    }
    Saturday, March 31, 2007 8:49 AM
  • if we have not defined a copy constructor then the compiler automatically makes a copy constructor or bit-by-bit copy is done??

    i found this in sumita arora(i know it is aa real *** book but i have to follow it fr my cbse curriculum and write watever *** is there in ti in tests )

    class A
    {
    public:
    A(){cout<<"Constructing";};
    ~A(){cout<<"Destructing";};
    };

    .
    .
    .

    void fun(A a);

    .
    .
    .

    int main()
    {
    A a;
    fun(a);
    }

    the o/p was

    destructing

    she was saying the constructor is not used...i instead added a copy constructor and found that the copy constructor was being used as i had expected.

    my question is that cud bitwise copty have taken place and constructor ACTUALLY not called???

    my second question why we always use pass by value in copy constructor???

    the explaination i have thought fr this is based on fact that copy constructor is called in pass by value...that an infinite loop of copy constructors will be called (somethign like recursion...copy constructor calling itself again and again). is this the correct reason or there is sum other reason.
    Saturday, March 31, 2007 8:51 AM

  • what is containership in c++ and nested class
    Saturday, March 31, 2007 8:52 AM
  • Check it out yourself
    May be the error will be :-
    Misplaced Continue, or something like that...

    Do check for these elementary questions on your compiler by writing small code snippets...
    And moreover, start some good book in C, one of those mentioned in the FAQs of this community, if you really want to learn Programming..
    Cheers !!
    Saturday, March 31, 2007 9:25 AM
  • is preprocessor directive this is used to include header files like #include<stdio.h>
    Saturday, March 31, 2007 9:27 AM
  • Well it expects you to not use it. If you do, remember smoking is injurious to health. Either you can stop smoking or stop reading such warnings. Smile
    Saturday, March 31, 2007 9:30 AM
  • Hmmm...you are printing out nothing. So why would there be an output?

    And assuming you want to know what a's value would be, check out what happens in integer division when the numerator is less than the denominator.

    PS : - Couldn't you have compiled and tried this out yourself?
    Saturday, March 31, 2007 9:31 AM
  • memcpy((void*)str,(void*)&flt,sizeof(flt));

    Why should you ever need to type cast to void* ?
    Anyway seg fault is obvious, you are copying 8 bytes (Assuming float is 8 bytes) into a location which is of 3 bytes.
    Saturday, March 31, 2007 9:31 AM
  • Advantage : You can instantiate an object from another object of the same class or from that of a derived class.

    Disadvantage : A bad programmer may not write it properly or may rely on the one that is synthesized for him/her by the compiler. Not exactly a disadvantage but maybe that is what your interviewer is looking for.
    Saturday, March 31, 2007 9:33 AM
  • The answer depends on whether the first number in each line always represents the line number from which to get the input, and whether the sequence is monotonically increasing

    For e.g , is this a valid input file

    1 asd
    2 dsfe
    5 nfife
    8 yabbadabbadoo
    6 Umm

    I think you need to be more specific.
    One you *are* more specific, let us know what you have tried so far, and then we can take it from there. Dont expect to be spoon fed though
    Saturday, March 31, 2007 10:02 AM
  • oid * can take anything, so you need not type cast.

    What exactly do you want, this will write bit pattern of float variable into str, why do you need it ? You may want to use snprintf() actually.

    And how can I forget

    char *str = "str";
    str is read only, you are trying to write into a read only location.
    Saturday, March 31, 2007 10:03 AM
  • SCII values for arrow keys are:

    72 is for UP arrow key
    75 is for LEFT arrow key
    77 is for RIGHT arrow key
    80 is for DOWN arrow key

    PS: 13 is for ENTER key
    Saturday, March 31, 2007 10:11 AM
  • WHILE(FILE)
    {
    FILE.READ((CHAR*)&OBJ,SIZEOF(OBJ);
    PUTDATA();
    } WILL PRINT THE THE LAST OBJECT IN THE FILE FOR TWO TIMES....... WHY THIS IS HAPPENING..... I KNOW THE ALTERNATE WAY FOR PRINTING IT ONLY ONCE... BUT MY QUESTION IS WHY IT IS PRINTING TWICE IN ABOVE TYPE FUNCTION



    because as read ptr reaches to last object.... prog. print it.. but at this time file handler doesn't encounter the 'eof' so while loop will be executed for next time too..... and this time file ptr encounter 'eof' so read sys call fails so obj will contain the same same data as last one.... and prog. wil print it..
    Saturday, March 31, 2007 10:15 AM
  • Why redirect it to a file, just try executing, you wont see anything on screen :-)
    This is funny but sometime you must flush(stdout). Add fflush(stdout) after printf(), it should work.
    Saturday, March 31, 2007 10:18 AM
  • Syntactically they are different ofcourse and even conceptually they are quite different as well. Infact they model totally different kind of relationship.

    When I say Inheritance(Public), the most important point is substitutability. (A function expecting Base Class pointer/reference can be provided a Derived class pointer/Reference)The relationship being modeled here is type of "IS A". A "Professor" "is a" "Employee" after all.

    You also have Composition. When a Class contains an object of another class. Suppose your main class is Car and you have kept an object of type Engine inside it. The relationship being modeled here is "HAS A" type of relationship. "Car" "has a" "Engine."

    Nested Class's scope obviously is restricted by the enclosing class. Like a member of the surrounding class. Its more like the Nested class makes sense only in the context of its enclosing class.It has access to all its enclosing class's members. The relationship being modeled here is "Is Implemented In Terms Of" relationship.


    You can and would like to consult Scott Meyers for a more detailed insight into all the kind of relationship that might exist between two classes.
    Saturday, March 31, 2007 10:19 AM
  • Common sense tells you that it would be a parsing nightmare if it were allowed, e.g.

    x = y+;
    Saturday, March 31, 2007 10:20 AM
  • I wont talk about C++. Not my area.

    The behavior of vfork () or rather how different it is from fork () is implementation specific. vfork () kind of assumes ( on most implementations) that the user will overlay the image of the current executable with another new one and not misuse it.



    Saturday, March 31, 2007 10:21 AM
  • solution in c for printing the number in words
    int main()
    {
    int digitDevil,j=0,n;
    printf("enter a number");
    scanf("%d",&n);
    do
    {
    digit[j]=n%10;
    j++;
    n/=10;
    }while(n>0)
    for(i--,i>0;i--)
    {
    switch(digit[j])
    {
    case 0:
    printf("zero");
    break;
    case 1:
    printf("one");
    break;
    case 2:
    printf("two");
    break;
    case 3:
    printf("three");
    break;
    case 4:
    printf("four");
    break;
    case 5:
    printf("five");
    break;
    case 6:
    printf("six");
    break;
    case 7:
    printf("seven");
    break;
    case 8:
    printf("eight");
    break;
    case 9:
    printf("nine");
    break;
    }
    }
    }
    Saturday, March 31, 2007 10:27 AM
  • about mistake
    hello MR...,
    I m jay i test your code ......
    there is no problem init. constructor is called and also destructor is also called where is the problem....
    "
    #include<iostream.h>

    class A
    {
    public:
    A(){cout<<"Constructing";};
    ~A(){cout<<"Destructing";};
    };
    void fun(A a)
    {
    cout<<"hello";

    }
    int main()
    {
    A a;
    fun(a);
    return(0);

    }
    "

    output is::
    Constructing hello Destructing Destructing........
    who said the constructor is not called????????????????
    Saturday, March 31, 2007 10:29 AM
  • containment
    class B {};
    class A {
    B b;
    };

    Nested class

    class A {
    class B {
    };
    B b;
    };
    Saturday, March 31, 2007 10:30 AM

  • that runs on a double click of the mouse !
    Saturday, March 31, 2007 10:44 AM

  • I read it from The Complete Reference, Fourth Edition
    by Herbert Schildt................

    When a function is declared as virtual by a base class, it may be overridden by a derived class. However, the function does not have to be overridden.When a derived class fails to override a virtual function, then when an object of that derived class accesses that function, the function defined by the base class is used.

    Is it correct?
    Saturday, March 31, 2007 10:45 AM

  • how to sort data in increasing order in a multidimensional array...

    eg: 3 1
    7 6

    0/p: 1 3
    6 7
    Saturday, March 31, 2007 10:46 AM

  • what is the use of static function is a c++ program... when should i use static function..
    Saturday, March 31, 2007 10:48 AM
  • Man please keep this thread going. After reading this, i came to know that balaguru and kanetkar's books are really for beginners, and not going to do any good for your career, and further in-depth knowledge.

    I really learned a lot from reading this thead Smile
    Sunday, April 29, 2007 5:16 PM
  • Static functions are used to access the Static data members of a class...
    As static data memebers are common for all the objects they are created... they cannot be invoked using a object... so the standard functions cannot be used if we want to specially use this values.. though the standard functions have right to use this data members...

    But lets say I use a static data member to count the number of objects created, and i want to see this value... I can create a static function to see this value.. now this functions are called directly using the class name, i.e. no object required..

    This is the best example i could give
    Sunday, April 29, 2007 6:28 PM
  • An empty class is ones that does not have any member datum, then , even on object creation, the size of the object itself should be zero. If that is the case, then if I create an array of objects, say 100 objects of class A (say), then no memory will be assigned to any of the member objects.

    To overcome this, C++ puts in the size of an empty class to 1 byte. That's ensures that all objects of a class will always be assigned memory irrespective of whether the class itself contains data members or not.
    Thursday, May 24, 2007 10:58 AM
  • Good one Raghuram.. I didnt knew that....
    Thursday, May 24, 2007 11:14 AM
  • Correct answer raghuram....
    Thursday, May 24, 2007 1:12 PM
  • Member Function is a function declared in the scope of a class. A member function that is not a static member function must be called for an object of its class.

    In OOP when a derived class inherits from a base class, an object of the derived class may be referred to (or cast) as either being the base class type or the derived class type. If there are base class functions overridden by the derived class, a problem then arises when a derived object has been cast as the base class type. When a derived object is referred to as being of the base's type, the desired function call behavior is ambiguous.

    The distinction between virtual and not virtual is provided to solve this issue. If the function in question is designated "virtual" then the derived class's function would be called (if it exists). If it is not virtual, the base class's function would be called.

    Thus a member function is not made a virtual function by default and the choice is left to the user, to be able to call  the derived class's function or the base class's function without any ambiguity.



    Friday, May 25, 2007 10:44 AM
  • Good explanation Arijit. Thanks for the answer.
    Friday, May 25, 2007 11:53 AM
  • good detailed answer. let me answer it shortly

    Member functions are not virtual by default  Because many classes are not designed to be used as base classes. Virtual functions make sense only in classes meant to act as interfaces to objects of derived classes (typically allocated on a heap and accessed through pointers or references).


    Friday, May 25, 2007 1:14 PM
  • @ Anoop....BULLS EYE m8

    Short,Precise and Correct Answer!!
    Friday, May 25, 2007 1:17 PM
  • Well that was short and sweet, i have a even more shorter answer...
    Virtual functions are used mainly for Run time polymorphisms, which is not the usual case.. so we dont have functions virtual by default...

    And guys can you shift to a new thread.. its very hard to navigate here.. and dont forget to post the link here....

    Friday, May 25, 2007 1:39 PM
  • Nice explaination , its the answer is getting smaller and smaller. I think there should be a competition, smallest definition wins Smile

    I dont think i can give a smaller definition than Varun's Stick out tongue

    Friday, May 25, 2007 2:17 PM
  • where's the next query?
    Sunday, May 27, 2007 12:54 PM
  • Monday, May 28, 2007 3:10 PM
  • anywhere but not necessarily  in contiguous memory locations
    Monday, May 28, 2007 3:21 PM
  • Well i think that they follow he same format as the natural data types like int, float etc...

    because class is a user defined  data type ...
    Monday, May 28, 2007 4:07 PM
  • that's what i said.
    by the way, MOdi , i am really impressed by your answers.
    what are you doing buddy?
    i'm final yr. CSE stud
    Tuesday, May 29, 2007 2:18 AM
  • Well, I m doing Mca, right now in 2nd sem end... That is the reason most of my answers are in C++, as i need to prepare it for exams...
    Tuesday, May 29, 2007 4:27 AM
  • new thread in continuation to this 1.
    http://forums.microsoft.com/SamVaad/ShowPost.aspx?PostID=1661006&SiteID=43&mode=1
    Tuesday, May 29, 2007 12:06 PM
  • Answer

    Like C, C++ doesn't define layouts, just semantic constraints that must be met. Therefore different implementations do things differently. Unfortunately, the best explanation I know of is in a book that is otherwise outdated and doesn't describe any current C++ implementation: The Annotated C++ Reference Manual (usually called the ARM). It has diagrams of key layout examples. There is a very brief explanation in Chapter 2 of TC++PL.

    Basically, C++ constructs objects simply by concatenating sub objects. Thus

            struct A { int a,b; };
    
    is represented by two ints next to each other, and
            struct B : A { int c; };
    
    is represented by an A followed by an int; that is, by three ints next to each other.

    Virtual functions are typically implemented by adding a pointer (the vptr) to each object of a class with virtual functions. This pointer points to the appropriate table of functions (the vtbl). Each class has its own vtbl shared by all objects of that class.

    Wednesday, May 30, 2007 6:01 PM
  • Hello evrybody,

    Now i am learnin C programming ,can u help me reading........??

    just give me sum sample programsor url to download some sample programs...

     

    Sunday, December 9, 2007 2:36 AM
  • hi,

     

    the keyword virtual refers to that itshould be overridden . since constructors cannot be overridden so we can't and moreover we can't create a constructor of one class in another class.

    Saturday, December 15, 2007 8:28 AM
  •  V N RAGHAVENDRA _VINNAKOTA_c2a3a wrote:

    1. A majority element in an array A, of size N is an element that appears more than N/2 times (and hence there is atmost
    one such element)

    Write a function which takes an array and emits the majority element (if it exists), otherwise prints NONE as follows:

    I/P : 3 3 4 2 4 4 2 4 4
    O/P : 4

    I/P : 3 3 4 2 4 4 2 4
    O/P : NONE

    2. How do u find the largest repeating string and the number of times it
    repeats in a given string efficiently offcourse !?

    ex :
    String : "abc fghi bc kl abcd lkm abcdefg"
    Ans : "abcd" count = 2

    3. Given an array of numbers, except for one number all the others, occurs twice. Give an algorithm to find that number which occurs only once in the array.

    Can you send me the answers?
    Tuesday, March 11, 2008 3:57 PM

  • A valuable thread .....

    Really Nice !!!!!!!!!!!!!!!
    Thursday, March 13, 2008 6:00 AM
  •  

    Hi !

     

    I have to develop a GCD(Greatest Common Divisor) software which finds the common divisors of a list of given numbers. I must get numbers into a linked list. The divisors must be stored in a stack.

     

    Can you help me ???

    Tuesday, April 8, 2008 11:30 AM