Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

You must login to add post.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

mcqoptions.com

mcqoptions.com Logo mcqoptions.com Logo

mcqoptions.com Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/Waves
  • Recent Questions
  • Most Answered
  • Answers
  • No Answers
  • Most Visited
  • Most Voted
  • Random
  1. Asked: 3 years agoIn: Pointers

    Write a function substr() that will scan a string for the occurrence of a give substring. the prototype of the function would be:

    char *substr(char *string1,char string2);

    The function should return a pointer to the element in string1 where strig2 begins. If string2 doesn’t occur in string1 then substr() should return a NULL.

    For example, if string1 is “Ena Meena Deeka”, and string2 is “Meena” the substr() should return address of ‘M’ in string1. 

    Write main() function also that uses the function substr().

    eac99
    Added an answer about 3 years ago

    #include <iostream.h>#include<stdio.h>char *get_substr(char *sub, char *str);int main(){ char *substr,*str; cout<<"Enter the string :"; gets(str); cout<<"\nEnter the substring :"; gets(substr); substr = get_substr(substr,str); if (substr!='\0') cout << "substring found:Read more

    #include <iostream.h>

    #include<stdio.h>

    char *get_substr(char *sub, char *str);

    int main()

    {

     char *substr,*str;

     cout<<“Enter the string :”;

     gets(str);

     cout<<“\nEnter the substring :”;

     gets(substr);

     substr = get_substr(substr,str);

     if (substr!=’\0′)

     cout << “substring found: ” <<substr;

     else

     cout<< “substring not found”;

     return 0;

    }

    char *get_substr(char *sub, char *str) // Return pointer to substring or

    null if not found.

    {

     int t;

    char *p, *p2, *start;

    for(t=0; str[t]!=’\0′; t++)

    {

    p = &str[t];

    start = p;

    p2 = sub; 

     while(*p2!=’\0′ && *p2==*p) // check for substring

    {

    p++;

    p2++;

    }

    /* If at end of p2 (i.e., substring), then a match has been found. */ if(!*p2)

    return start; // return pointer to beginning of substring 

    }

    return 0;

    }

    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Asked: 3 years agoIn: Pointers

    What is the advantage of passing arguments by reference? When and why is passing an object by reference preferable? 

    cb0e3
    Added an answer about 3 years ago

    In passing arguments by reference method, the called function does not create its own copy of original values; rather, it refers to the original values only by different names i.e., the references. Thus the called function works with the original data and any change in the values gets reflected to tRead more

    In passing arguments by reference method, the called function does not create its own copy of original values; rather, it refers to the original values only by different names i.e., the references. Thus the called function works with the original data and any change in the values gets reflected to the data. The passing an object by reference method is preferable in situations where we want the called function to work with the original object so that there is no need to create and destroy the copy of it.

    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  3. Asked: 3 years agoIn: Pointers

    Write a function having this prototype:

    int replace(char *s,char c1,char c2); Have the function replace every occurrence of c1 in the string s with c2, ad have the function return the number of replacements it makes.

    3c3e8
    Added an answer about 3 years ago

    int replace(char * str, char c1, char c2){int count = 0;while (*str) // while not at end of string{  if (*str == c1){ *str = c2;count++;} str++; // advance to next character}return count;}

    int replace(char * str, char c1, char c2)

    {

    int count = 0;

    while (*str) // while not at end of string

    { 

     if (*str == c1)

    { 

    *str = c2;

    count++;

    } str++; // advance to next character

    }

    return count;

    }

    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  4. Asked: 3 years agoIn: Pointers

    Given here is a structure defilation:

    struct Box {  char maker[21];

    float height,width,length,volume;

    };

    Write a function that passes the address of a Box structure and that sets the volume member to the product of the other three dimensions.

    66248
    Added an answer about 3 years ago

    #include<iostream.h>struct box{char maker[40];float height;float width;float length;float volume;};box yours;float boxer_dimensions (const box * compute );void display_box (const box make);int main(){box yours ={"Apple", 10.0, 5.0,7.5};// to initialize a recordchar name[40];float dia;dia= boxeRead more

    #include<iostream.h>

    struct box

    {

    char maker[40];

    float height;

    float width;

    float length;

    float volume;

    };

    box yours;

    float boxer_dimensions (const box * compute );

    void display_box (const box make);

    int main()

    {

    box yours ={“Apple”, 10.0, 5.0,7.5};// to initialize a record

    char name[40];

    float dia;

    dia= boxer_dimensions (&yours); //function call

    yours.volume = dia;// assigning results to volume member record

    display_box (yours);// function call

    return 0;

    }

    float boxer_dimensions (const box *compute )// specs calls for passing address of the structure

    {

     float Vol;

    Vol= ((compute->height)*(compute->length)*(compute->width));

    //computation for volume here

    return Vol;

    }

    void display_box (const box make)/// display all results here

    {

    cout << make.maker <<endl;

    cout << make.height <<endl;

    cout << make.width <<endl;

    cout << make.length<< endl;

    cout << make.volume<<endl;

    }

    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  5. Asked: 3 years agoIn: Pointers

    C++ lets you pass a structure by value and it lets you pass the address of a structure. If sample is a structure variable, how would you pass it by value? How would you pass its address? Which method do you think is better?

    18349
    Added an answer about 3 years ago

    If we assume structure variable name as sample and function name as sample_function() then:Pass a structure by valuePass a structure by address struct SAMPLE sample; sample_function(sample);void sample_function(struct SAMPLE sample)  : :}struct SAMPLE sample;sample_function(&sample);void sample_Read more

    If we assume structure variable name as sample and function name as sample_function() then:

    Pass a structure by value Pass a structure by address 
    struct SAMPLE sample; sample_function(sample);
    void sample_function(struct SAMPLE sample) 
     
    :
     :
    }
    struct SAMPLE sample;

    sample_function(&sample);
    void sample_function(struct SAMPLE *sample)
    {
    :
    :
    }

    Both the method have their own importance, so as per the program requirement we can use any of them.

    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  6. Asked: 3 years agoIn: Pointers

    Imagine a publishing company that markets both books and audio-cassette versions of its works. Create a class called Publication that stores the title (a string) and price of a publication. From this class derive two classes: Book, which adds a page count (type int); and Tape, which adds a playing time in minutes (type float). Each of the three class should have a getdata() function to get its data from the user at the keyboard, and a putdata() function to display the data. Write a main() program that creates an array of pointers to Publication. In a loop, ask the user for data about a particular book or Tape, and use new to create a object of type Book or Tape to hold the data. Put the pointer to the object in the data for all books and tapes, display the resulting data for all the books and taps entered, using a for loop and a single statement such as

    pubarr[i]->putdata();

    to display the data from each object in the array.

    1cf0b
    Added an answer about 3 years ago

    #include<iostream.h>#include<string.h>class Publication{private: char title[20]; float price;public: void getName() {cout<<"Enter Title: "; cin>>title;cout<<"Enter Price: $"; cin>>price; } void putName() {cout<<"\nTitle: "<<title;cout<<", Price:Read more

    #include<iostream.h>

    #include<string.h>

    class Publication

    {

    private:

     char title[20];

     float price;

    public:

     void getName()

     {

    cout<<“Enter Title: “; cin>>title;

    cout<<“Enter Price: $”; cin>>price;

     }

     void putName()

     {

    cout<<“\nTitle: “<<title;

    cout<<“, Price: $”<<price;

     }

     virtual void getData() = 0;

    };

    class Book : public Publication

    {

    private:

     int pages;

    public:

     void getData()

     {

     Publication::getName();

    cout<<“Enter Pages: “; cin>>pages;

     }

     void putData()

     {

     Publication::putName();

    cout<<“, Pages: “<<pages<<end1;

     }

    };

    class Tape : public Publication

    {

    private:

     float minutes;

    public:

     void getData()

     {

     Publication::getName();

    cout<<“Enter Minutes: “; cin>>minutes;

     }

     void putData()

     {

     Publication::putName();

    cout<<“, Minutes: “<<minutes<<end1;

     }

    };

    int main()

    {

     Publication* ptrPub[100];

     int n = 0;

     char choice;

     do

     {

    cout<<“Book or Tape? (b/t): “; cin>>choice;

    if(choice == ‘b’)

     { ptrPub[n] = new Book; ptrPub[n]->getData(); }

     else

     { ptrPub[n] = new Tape; ptrPub[n]->getData(); }

    n++; cout<<“Enter another? (y/n): “; cin>>choice;

     } while(choice == ‘y’);

     for(int i=0; i<n; i++)

     ptrPub[i]->putName();

     cout<<end1;

     return 0;

    }

    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  7. Asked: 3 years agoIn: Pointers

    Suppose 7 names are stored in a array of pointers names[] as shown below:

    char *names [ ]= { “Anand”,”Naureen”,”Banjot”,”Wahid”,”sheena” }; 

    Write a program to reverse the order of these names.

    7b590
    Added an answer about 3 years ago

    #include<iostream.h>#include<conio.h>#include<string.h>void main(){clrscr();char *name[]={"anand","naureen","banjot","wahid","sheena"};int i,j;cout<<"\nOriginal string\n";for(i=0;i<5;i++)cout<<name[i]<<end1;char *t;for(i=0,j=4;i<5/2;i++,j--){t=name[i];name[iRead more

    #include<iostream.h>

    #include<conio.h>

    #include<string.h>

    void main()

    {

    clrscr();

    char *name[]={“anand”,”naureen”,”banjot”,”wahid”,”sheena”};

    int i,j;

    cout<<“\nOriginal string\n”;

    for(i=0;i<5;i++)

    cout<<name[i]<<end1;

    char *t;

    for(i=0,j=4;i<5/2;i++,j–)

    {

    t=name[i];

    name[i]=name[j];

    name[j]=t;

    }

    cout<<“\nReversed string:\n”;

    for(i=0;i<5;i++)

    cout<<name[i]<<end1;

    getch();

    }

    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 500k
  • Answers 393k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Aditi Dugal

    How to approach applying for a job at a company ...

    • 7 Answers
  • Raghavan Prasad Hayer

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Ankita Dinesh Biswas

    What is a programmer’s life like?

    • 5 Answers
  • 47e0c
    47e0c added an answer Correct Answer - Increasing the yield of animals and improving… November 12, 2022 at 9:56 am
  • b6699
    b6699 added an answer Sender\'s addressDateReceivers name and addressSubjectContentYours faithfullyName November 12, 2022 at 9:56 am
  • 10eb8
    10eb8 added an answer Any uncertinity in measurment is known as errorDifference in true… November 12, 2022 at 9:56 am

Top Members

Trending Tags

Class 11 Parabola Polity Polynomials Probability Projectile Protists Quadrilaterals Rario Reasoning Sampling Social Solutions Spectroscopy Switchgear Thermodynamic Tourism Transients Upsc Wbjee

Explore

  • Home
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Tags
  • Badges
  • Users

Footer

mcqoptions.com

About

MCQOptions.com

Here are the top interview questions, example answers, tips for giving the best response.

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Follow

© 2022 MCQOptions. All Rights Reserved