5th c++ Problem

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"<

Replies

  • Hussanal Faroke
    Hussanal Faroke
    pls explain ur questions a little more!
  • Manish Goyal
    Manish Goyal
    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
    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
    I think we should create a friend function for that class to change the value of its data members.
  • Manish Goyal
    Manish Goyal
    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
    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
    correct ...
    what about 2nd question?
  • Manish Goyal
    Manish Goyal
    The answer of 2nd question is you have to use some flags
    like left,right
    #include
    #include
    void main()
    {
    cout.setf(ios::left);
    cout<<"My name is manish"<for right you can use
    cout.setf(ios::right);

You are reading an archived discussion.

Related Posts

India is in a better position than its neighbours, Pakistan, Sri Lanka and Bangladesh when it comes to corruption. The latest CPI index ranks India on number 84 out of...
Hi, I need to bye a 2 gb DDR2 ram. I have already 1 gb ram of transcend. My shopkeeper says that there is no transcend ram available in the...
This is the tri series between the three teams 😀 First one is already over. SL vs BAN SL won in style. Dilshan made a century 😀
The Java Remote Method Invocation (RMI) system allows an object running in one Java virtual machine to invoke methods on an object running in another Java virtual machine. But Is...
GrabIt Version: 1.7.2 beta File Size: 2137 License: Free Browse and Search newsgroups without downloading headers! Automatically repair and extract downloaded binaries! SSL support to protect your download traffic! NZB...