Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 22nd, 2006, 12:26 PM
Authorized User
 
Join Date: Dec 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Class Specification... assistance required.

Hi,

I have recently been assigned to attempt the project below, and do not know where to start, if anyone could offer any advise or help, it would be very much appreciated...

Thank you for your time.

Nick.


The point P1 has coordinates {X1,Y1}.
The point P2 has coordinates {X2,Y2}.
The length of the line joining P1 and P2 is given by the equation:
{ (X2 - X1)2 + (Y2 - Y1)2 }1/2

Requirements:

Develop a class specification for the class Point (the data members and the prototypes for the member functions) in the file point.h.
Develop the implementation of the member functions in the file point.cc and test them with a suitable test program.
For example:
//pointTest.cc
int main()
{
     Point P1;
     P1.create(24,16); // create a point with coordinates {24,16}
     P1.display(); // display the {X,Y} coordinates of P1
     .....
}

Develop a class specification for the class Line (the data members and the prototypes for the member functions) in the file line.h.
Develop the implementation of the member functions in the file line.cc and test them with a suitable test program.
For example:
//lineTest.cc
int main()
{
     Point P1;
     P1.create(24,16); // create a point with coordinates {24,16}
     Point P2;
     P2.create(33,42); // create a point with coordinates {33,42}
     Line L1;
     L1.create(P1,P2); // create a line using points P1 and P2
     cout << L1.length() << endl; // display the length of line L1
     Line L2;
     L2.create(12,30,28,16); // create a line using coordinates {12,30}, {28,16}
     L2.display(); // display the coordinates of both points
     .....
}

Application:

I need to determine the length of the boundary of an irregular polygon.
The polygon may have up to 9 sides.
The user should be prompted to enter the number of sides and the coordinates of each vertex point.
The program should then calculate and display the total length of the boundary.
I will need to write a main function to implement this using your Point and Line classes and test the program thoroughly.

Reply With Quote
  #2 (permalink)  
Old March 23rd, 2006, 02:46 PM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is my questions:
Write an interactive program for a grocery store which will ask for the transaction year, user's name entering the data and will request from the user total monthly sales for each month through the year. The output will be the total sales per quarter, average quarterly sales, total annual sales and average annual sales.

What am I doing wrong

#include <iostream.h>


int main ( )
{

    int transYear, userName, num;
    double month1,month2,month3,month4,month5,month6,month7,m onth8,month9,month10,month11,month12;
    double qrt1, qrt2, qrt3, qrt4, qrtAvg, annlSales, annlAvg;

    qrtAvg = (qrt1+qrt2+qrt3+qrt4)/4;
    annlSales = (month1+month2+month3+month4+month5+month6+month7+ month8+month9+month10+month11+month12);
    annlAvg = (month1+month2+month3+month4+month5+month6+month7+ month8+month9+month10+month11+month12)/12;

    cout << "Enter transaction year: \n" ;
    cin >> transYear;
    cout << "Enter user name: \n";
    cin >> userName;

    cout << "Enter montly sales separated by space: ";
    cout << endl;
    cin >> month1>> month2>> month3>> month4>> month5>> month6>> month7>> month8>> month9>> month10>> month11>> month12;

    cout << "Sales per quarter are: \n" << qrt1 << "\n"<< qrt2 <<"\n"<< qrt3 <<"\n"<< qrt4;
    cout << endl;
    cout << "Average quarterly sales are: \n" << qrtAvg;
    cout << endl;
    cout << "Total annual sales are: \n" << annlSales;


return 0;

}

Reply With Quote
  #3 (permalink)  
Old April 7th, 2006, 06:17 AM
Authorized User
 
Join Date: Oct 2004
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to C@uark
Default

Think about the flow of controll, your code makes no since:

You declare some variables with(this is fine, however it is best to initialize upon declaration i.e. double month1 = 0.0):

int transYear, userName, num; // user Name would usually make people think of a string not really an integer

double month1,month2,month3,month4,month5,month6,month7,m onth8,month9,month10,month11,month12;
double qrt1, qrt2, qrt3, qrt4, qrtAvg, annlSales, annlAvg;

Then you try to set some of them with variables that are useless i.e.(uninitialized/have no usefull values):

qrtAvg = (qrt1+qrt2+qrt3+qrt4)/4; // hear you have junk/4 becuase qrt has no real value
annlSales = (month1+month2+month3+month4+month5+month6+month7+ month8+month9+month10+month11+month12); //same here
annlAvg = (month1+month2+month3+month4+month5+month6+month7+ month8+month9+month10+month11+month12)/12; //dido

Then you have some user i/o (this looks fine,but may be problamatic):

cout << "Enter transaction year: \n" ;
cin >> transYear;
cout << "Enter user name: \n";

cin >> userName; // this line will not cause a compile error how ever when the user tries to input a string(there name) cin will set the fail bit flag and you will have a bad read because you have declared it as integer or it will only read the first character of there name in as an integer, either way i would assume that is not the desired outcome.

cout << "Enter montly sales separated by space: ";
cout << endl;
cin >> month1>> month2>> month3>> month4>> month5>> month6>> month7>> month8>> month9>> month10>> month11>>month12;

Then you try to use variables again that have no reall values:

cout << "Sales per quarter are: \n" << qrt1 << "\n"<< qrt2 <<"\n"<< qrt3 <<"\n"<< qrt4; // sending junk to the std out
cout << endl;
cout << "Average quarterly sales are: \n" << qrtAvg; //same here
cout << endl;
cout << "Total annual sales are: \n" << annlSales; //same here

think about what I am saying here rearrange some stuff get some meaningfull data and you should have everything you need.
Reply With Quote
  #4 (permalink)  
Old July 31st, 2006, 11:13 AM
Registered User
 
Join Date: Jul 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi neeko, i guess you have the solutions by now. can u plz e-mail me solutions. i think the files are: line.h, line.cc, point.h, point.cc and if possible the application testing program and results. i would really apreciate it if u send it to my email address: [email protected]

thank you.

Reply With Quote
  #5 (permalink)  
Old August 10th, 2006, 10:34 AM
Registered User
 
Join Date: Jul 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey ....
i know this kind of problems...I had them when i was programming in C/C++...
But since i found the D language those are all gone...:)
http://www.digitalmars.com/d/

and here are some sites found with codecity.org
http://www.codecity.org/index.php?c=Languages/D

Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Assistance Understanding Timer Class lnickol22 Pro Visual Basic 2005 2 January 14th, 2008 05:07 PM
Computed Column Specification olisav ASP.NET 2.0 Basics 0 May 14th, 2007 04:00 PM
Invalid authorization specification rcatal01 JSP Basics 10 April 20th, 2005 09:02 AM
Bounce-path Specification pavanp .NET Web Services 0 February 1st, 2005 10:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.