homework question - Standard Libraries

This is a discussion on homework question - Standard Libraries within the C++ Programming forums, part of the General Programming Boards category; Hello guys! As you can tell its about standard libraries. I need to turn it in soon, but can not ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    72

    homework question - Standard Libraries

    Hello guys! As you can tell its about standard libraries. I need to turn it in soon, but can not get a hold of the teacher.

    This is the code it's based on.

    Code:
    #include <iostream>
    using namespace std;
    #include "C:\\Dev-Cpp\\user_area\\udst_monitor.h"
    
    // Function Prototypes
    
    double area_square(double side);
    double area_rectangle(double side1, double side2);
    double area_circle(double radius);
    double area_trapezoid(double base, double top, double height);
    
    // Variables
    
    double  square_room_size;
    double  driveway_length;
    double  driveway_width;
    double  swimming_pool_diameter;
    double  trap_bottom;
    double  trap_top;
    double  trap_height;
    
    //******************************************************
    // main
    //******************************************************
    
    int main(void)
      {
      // *************************** square
      // Input Test Data - 4.5
      cout << "\nWhat is the length of one of the walls in your square bedroom? -->: ";
      cin >> square_room_size;
      // Output Test Results - 20.25
      cout << "\nYour room is " << area_square(square_room_size) << " square whatevers.\n";
      pause_m();
      clear_m();
      
      // *************************** rectangle
      // Input Test Data - 4.5
      cout << "\nWhat is the length of your driveway? -->: ";
      cin >> driveway_length;
      // Input Test Data - 6.6
      cout << "\nWhat is the width of your driveway? --->: ";
      cin >> driveway_width;
      // Output Test Results - 29.7
    
      cout << "\nYour driveway is " << area_rectangle(driveway_length, driveway_width) << " square whatevers.\n";
      pause_m();
      clear_m();
      
      // *************************** circle
      // Input Test Data - 13.8
      cout << "\nWhat is the diameter of your circular swimming_pool? -->: ";
      cin >> swimming_pool_diameter;
      // Output Test Results - 149.571
      cout << "\nYour pool is " << area_circle(swimming_pool_diameter / 2) << " square whatevers.\n";
      pause_m();
      clear_m();
      
      // *************************** trapezoid
      // Input Test Data - 12.7
      cout << "\nWhat is the length of the bottom side of your trapezoid? -->: ";
      cin >> trap_bottom;
      // Input Test Data - 9.3
      cout << "\nWhat is the length of the top side of your trapezoid? ----->: ";
      cin >> trap_top;
      // Input Test Data - 4.2
      cout << "\nHow tall is your trapezoid? ------------------------------->: ";
      cin >> trap_height;
      // Output Test Results - 46.2
      cout << "\nYour trapezoid is " << area_trapezoid(trap_bottom, trap_top, trap_height) << " square whatevers.\n";
      pause_m();
      clear_m();
      
      return 0;
      }
    
    //******************************************************
    // area_square
    //******************************************************
    
    double area_square(double side)
      {
      return side * side;
      }
    
    //******************************************************
    // area_rectangle
    //******************************************************
    
    double area_rectangle(double side1, double side2)
      {
      return side1 * side2;
      }
    
    //******************************************************
    // area_circle
    //******************************************************
    
    double area_circle(double radius)
      {
      return 3.14159265 * radius * radius;
      }
    
    //******************************************************
    // area_trapezoid
    //******************************************************
    
    double area_trapezoid(double base, double top, double height)
      {
      return (base + top) / 2 * height;
      }
    We need to creat a function called "area_triangle" , prototype it and within the function main we need to add an area for calling the function.

    But I have no idea what he means by "area_triangle"? Does anybody know what that is supposed to do?

  2. #2
    Registered User
    Join Date
    May 2008
    Posts
    15
    The normal way to calculate the area of a triangle would be to take 1/2(Base * Height).

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    72
    Thanks. So in this case 0.5(area_square * Height) ? ops no, its base. Nevermind then.
    Last edited by XodoX; 02-24-2009 at 06:57 PM.

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    BTW, you should never put a using statement before any #include statements, otherwise you might change the meaning of some of the code in the header file.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,170
    Quote Originally Posted by rt454 View Post
    The normal way to calculate the area of a triangle would be to take 1/2(Base * Height).
    I find it more obvious to say it's

    Base * Height / 2
    Or just
    Base * Height * 0.5
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    > #include "C:\\Dev-Cpp\\user_area\\udst_monitor.h"
    This should be
    #include "udst_monitor.h"

    Then in the compiler project settings, you add the path to the pre-processor search directories.
    Something like
    -IC:\Dev-Cpp\user_area

    > // Variables
    > double square_room_size;
    All these variables should be local to main
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The closest to a homework question without it being locked
    By DanFraser in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 01-28-2009, 02:25 AM
  2. C++ Standard and one question
    By Jorl17 in forum C++ Programming
    Replies: 12
    Last Post: 10-30-2008, 03:49 PM
  3. Another Homework Question
    By Trekkie in forum C++ Programming
    Replies: 3
    Last Post: 10-20-2005, 06:57 AM
  4. Urgent - Help - Homework Question
    By Sway2 in forum C++ Programming
    Replies: 12
    Last Post: 10-04-2002, 01:35 PM
  5. I have a homework question?
    By correlcj in forum C++ Programming
    Replies: 4
    Last Post: 10-03-2002, 10:38 PM

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