5th c++ Problem

Manish Goyal

Manish Goyal

@manish-r2Hoep Oct 13, 2024
1:-By default you can't change data members of a constant object..
But it can be made to do so...
can you give me method?

2:-By default all the output in c++ are right justify
can you give me method to have output that are left justify?
Please don't use output like this............

cout<<" Hello"<<endl;

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Hussanal Faroke

    Hussanal Faroke

    @hussanal-faroke-U5nNM8 Jan 4, 2010

    pls explain ur questions a little more!
  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep Jan 4, 2010

    3 :- Say you have created a class named car ...whose data members are
    name,owner,model
    since model and name of car can't be changed .in any case ...so you will create a constant object of type car so that if you ever tried to change name and model ..compiler gives you an error..
    but owner of car can be changed now since you have declared a constant object of type car ..compiler will not allow you
    Now My question is ..to give me some method..that i can achieve my both purpose that i can declare a constant object and it will also let me to change name of owner..
    I hope now you got my question
    2:-------Problem is quite simple...
    whenever you execute a Program ..It's output is right justify
    say you have to print "My name is hussanal"
    By default it will print like this:-

    My Name is hussanal

    But I want output which should be displayed on opposite side ...........
  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep Jan 6, 2010

    what happen ceans no replies?
    Please give it a try or i am just wasting database of ce by these questions?
    I think i should give you a clue
    1:-use some keyword ..there is only one keyword that can fulfill your purpose
    2:-use some flags
  • gaurav.bhorkar

    gaurav.bhorkar

    @gauravbhorkar-Pf9kZD Jan 6, 2010

    I think we should create a friend function for that class to change the value of its data members.
  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep Jan 6, 2010

    sorry Gaurav..by friend function also you can't change data members of constant object
    only one keyword dude..just one...******* char owner[10];
    like this
  • kagrawal85

    kagrawal85

    @kagrawal85-lwdytf Jan 6, 2010

    This can be done by declaring the data member of const object as mutable.By this Const function can change the mutable data member.Others will remain Constant.
  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep Jan 6, 2010

    correct ...
    what about 2nd question?
  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep Jan 6, 2010

    The answer of 2nd question is you have to use some flags
    like left,right
    #include<iostream.h>
    #include<conio.h>
    void main()
    {
    cout.setf(ios::left);
    cout<<"My name is manish"<<endl;
    }
    
    for right you can use
    cout.setf(ios::right);