You must Sign In to post a response.
  • Program to overload * operator using C++.


    Studying for object oriented programming exam? Having queries regarding usage of overload operator using C++? Check out this page where our ISC experts have provided answers for your questions.

    Following is a question that was asked in the question paper of II/IV B.Tech Degree Examinations,
    (April/May 2015)conducted by Acharya Nagarjuna University for subject Object Oriented Programming Systems, Semester-II

    Q) Write a program to overload the operator '*' to replicate a string for 'n' number of times (Ex. "ANU"*3 should result in "ANUANUANU"). [7 Marks]
  • Answers

    1 Answers found.
  • BELOW IS THE PROGRAM TO REPLICATE THE NAME FOR REQUIRED NUMBER OF TIMES USING OPERATOR OVERLOADING.
    Pleasse enter iostream.h and conio.h header files before declaration of class.
    #include
    #include
    class replica
    {
    private:
    char name[20];
    int n;
    public:
    void get(void)
    {
    cout<<"Enter the required name\n";
    cin>>name;
    }
    friend void operator*(replica s, int t)
    {
    for(int i=1;i<=t;i++)
    {
    cout< }
    }
    };
    void main(void)
    {
    class replica r;
    clrscr();
    r.get();
    int n;
    cout<<"\nEnter the number of times you want to repeate name\n";
    cin>>n;
    r*n;
    getch();
    }


  • Sign In to post your comments