Like Tree1Likes

Object-oriented Rectangle program

This is a discussion on Object-oriented Rectangle program within the C++ Programming forums, part of the General Programming Boards category; Clean and rebuild....

  1. #16
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,709
    Clean and rebuild.

  2. #17
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,635
    Quote Originally Posted by LearnOnTheFly View Post
    I tried your solution to no avail Elsyia. The output window come up but with no output. I receive this at the bottom when I try to debug:
    'Project1.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
    'Project1.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
    'Project1.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
    'Project1.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
    'Project1.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
    The thread 'Win32 Thread' (0x2ddc8) has exited with code -1073741510 (0xc000013a).
    The program '[160524] Project1.exe: Native' has exited with code -1073741510 (0xc000013a
    That is normal output. Nothing wrong there.
    You should be looking at the black console window that pops up.

    But I do have a program related question. I am supposed to redefine two of the objects and then print their outputs. How do I redefine an object. I have what I tried in comment brackets on my main.cpp and received an error when trying that.
    What does redefine mean in this context?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Registered User
    Join Date
    Mar 2012
    Posts
    98
    I have my 5 objects and I should print the length, width, area, and perimeter. Then I should set new parameter to object one and four and then print their values.

    And to the black window comment, nothing shows on it not even "..."
    Last edited by LearnOnTheFly; 02-17-2013 at 10:24 PM.

  4. #19
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    @LearnOnTheFly
    Please make sure you "paste as text" when copy/pasting things from your IDE.
    Your pastes are full of whatever passes for HTML, and it confuses the hell out of the board to make a decent presentation of it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #20
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,305
    Quote Originally Posted by LearnOnTheFly View Post
    Code:
    void Rectangle::setLength (double l)
    {
    if (l >= 0 && l <= 20)
            length = l;
    Please don't ever use a lowercase L as a variable name. It's what you call "asking for trouble".
    Salem likes this.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  6. #21
    Registered User
    Join Date
    Mar 2012
    Posts
    98
    Ok, thanks iMalc.

    I'm still struggling to solve how redefine objects. I have the five in man and then print their values. How can I set new parameters to the 2 of the objects after displaying the values, then display the new values?

  7. #22
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,635
    By calling appropriate member functions on the objects! You know the Rectangle is supposed to work, right?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    Registered User
    Join Date
    Mar 2012
    Posts
    98
    Got it. Sorry, it's taken a bit for object-oriented to soak in. Is there anyway to declare the object name in the print function. I know I can use a cout in main with each object name before calling the print function but I am supposed to use the print function for all display is possible.

    Also, how would you take the result from the boolean function and print "This is a square" if the result of the boolean function was true in the print the function. I know I can call the function but not sure how to write a cout statement based on the result. I have looked for examples with no luck.
    Last edited by LearnOnTheFly; 02-18-2013 at 07:38 PM.

  9. #24
    Registered User
    Join Date
    Mar 2012
    Posts
    98
    Ok, I have my boolean function working in print but when I set new values to object 1 from no parameters to length = 5.4 and width = 10.5 it says its still a square

    Code:
    int
    
     main()
    {
        Rectangle object1;
        Rectangle object2 (7.1, 3.5);
        Rectangle object3 (6.3);
        Rectangle object4 (21, 22);
        Rectangle object5 = object2;
        
        object1.printData();
        object2.printData();
        object3.printData();
        object4.printData();
        object5.printData();
        
        object1.setLength(5.4);
        object1.setWidth(10.5);
        
        object4.setLength(15.6);
        object4.setWidth(15.6);
        
        object1.printData();
        object4.printData();
    
        
    int c;
    
        
    while((c = getchar()) != '\n' && c != EOF);
        
    
    }
    Code:
     
     
    
     Rectangle::squareTest(double L, double W) const
    {
    if (L-W < .0001){
        return true;
    }
        
    else{
            return false;
    
    }
        
    }
    
    void Rectangle:printData()
    {
     cout<< "\nLength: " << length;
    
     cout<< "\nWidth: "<< width;
    
     cout<< "\nArea: " << calcArea();
    
     cout<"\nPerimeter: " << calcPerimeter();
    
    if (squareTest(length, width)){
        cout<<"\nThis is a square";
    }
        
    else{
        cout<<"\nThis is a rectangle";
     }

  10. #25
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,635
    Mmm, now would be an excellent time to try out the debugger.
    See if you can spot the error. Will do you good practice.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Object Oriented C
    By CSaw in forum C Programming
    Replies: 6
    Last Post: 07-06-2011, 05:06 AM
  2. Employee Object Oriented Program (3 files)
    By Bulls2012 in forum C++ Programming
    Replies: 1
    Last Post: 05-24-2011, 06:17 PM
  3. Object oriented SDL
    By jamort in forum Game Programming
    Replies: 3
    Last Post: 01-31-2011, 08:07 AM
  4. Replies: 1
    Last Post: 12-30-2007, 09:08 AM
  5. object oriented C
    By FlatLost in forum C Programming
    Replies: 4
    Last Post: 11-08-2005, 05:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21