Pages: 1234
ideas?
Ides google ide if your programing it is a 100% must to know the acronym
@nadeemzangi: Assuming the integrated development environment (IDE) that your using has a reasonable user interface, what product name is shown in the Help-->About dialog box? "5.1.0.0" and "6.1.0" are version numbers and do not tell us by themselves which product you are using.

@giblit: What are you trying to say with:

 Ides google ide if your programing it is a 100% must to know the acronym
I am tried for this program but I fail again and again.
I need help so please Friends Make me a program...
the problem statement is below.................

Problem Statement:
Write the C++ language program to calculate the slope of the line that is passing through two points and displays one of the following five messages according to the nature of the slope.

Message No Description
1 Line will make the 45 degree angle with the horizon
2 Line will travel more along X-Axis and Less along Y-Axis
3 Line will travel more along Y-Axis and Less along X-Axis
4 Line is parallel to Y-Axis.
5 Line is parallel to X-Axis.

Detailed Description:

Your program will ask for the two inputs for the starting point P1(x1,y1) of the line i.e. X-Coordinate and
Y-Coordinate, and two inputs for the ending point P2(x2,y2) of the line i.e. X-Coordinate and Y-Coordinate.

Formula to calculate the slope of the line is

Slope = difference between y coordinates/difference between x coordinates

Slope can be one of the following five types depending upon its value.

• Slope=1
Line will make the 45 degree angle with the horizon

• Slope<1
Line will travel more along X-Axis and Less along Y-Axis

• Slope>1
Line will travel more along Y-Axis and Less along X-Axis

• Your program should have a check for the value of difference between X coordinates of the two points i.e. dx. In case difference between x coordinates is zero then slope should not be calculated in your program and following message should be displayed.

Line is parallel to Y-Axis.

• Your program should have a check for the value of difference between Y coordinates of the two points i.e. dy. In case if the difference between y coordinates is zero then following message should be displayed.

Line is parallel to X-Axis.

For example Consider a line which passes through two points p1(10, 10) and p2(20, 18).
Your program should ask for X-coordinate of the starting point i.e. 10
Then it should prompt for the Y-coordinate of the starting point i.e. 10
Similarly your program will ask for the X and Y-coordinates of the ending point of the line i.e. 20 and 18 respectively.
Now difference between y coordinates is dy = = 18 – 10 = 8
Whereas difference between x coordinates is dx = = 20 – 10 = 10

Then message should be displayed according to the nature of the slope of the line. In this case following message will be displayed.

Line shall travel more along X-axis and Less along Y-axis.
You'd get same error with iostream
any One who make me Program for mY Program Statement ..
There is no point to helping you with your problem until we know which version of C++ your compiler or environment supports. Based on information given earlier, it is either very old or not installed correctly. As giblit says, you would immediately have a problem using most code someone wrote.

Besides this site is not a homework site so it is unlikely someone is going to give you a complete solution.

Try to compile and run each of the following programs. These are all programs edited (but not tested) from the "Structure of Program" documentation article on this site. If they give compilation errors, please identify what they are.

Number 1:

 123456 // Does nothing. int main () { return 0; }

Number 2:
 123456789 // Hello world with but no namespace. #include int main () { cout << "Hello World!"; return 0; }

Number 3:
 12345678910 // with iostream and namespace #include using namespace std; int main () { cout << "Hello World!"; return 0; }

I am expecting that the only one that will not give an error in your environment is Number 1. But until 1) and 3) both work for you, the people here will not be able to help you much. Because if 3) does not work, then either
a) you are using a C compiler and not a C++ compiler or
b) you are using a C++ compiler that is very old and does not support C++ standard from 1998 or C++ standard from 2003. [I am not enough of a C++ user to know which one added namespaces.]

Most are using newer compilers that support the language C++ define in the 2003 standard or the newer on.

If 1) and 2) work but not 3), then that will give us a clue about which version of C++ your compiler.
new Version C++ is________________________?
@FSchwartz I believe number two is supposed to be std::cout

and @Naz it shouldn't be this hard of a task to tell us what IDE you are using. Ex: Qt, Visual studio, Geany ect...
http://en.wikipedia.org/wiki/Integrated_development_environment
 Integrated development environments C and C++ Anjuta Code::Blocks CodeLite Dev-C++ Eclipse Geany GNAT Programming Studio KDevelop Kuzya MonoDevelop NetBeans QDevelop Qt Creator wxDev-C++ Ultimate++ Pelles C Sun Studio Xcode C++Builder CodeWarrior IBM VisualAge Visual Studio Express Java BlueJ Borland Latte BrewMaster Chicory Metrowerks CodeWarrior Pro for Java Cosmo Code Eclipse ED for Windows Forté for Java (superseded by NetBeans) FrIJDE(aka frigid) IntelliJ Geany Greenfoot Kalimantan Kawa KDevelop Java WebIDE Java WorkShop JavaMaker JBuilder JCreator JDeveloper JFactory jGRASP MyEclipse NetBeans NetCraft Object Engineering Workbench for Java (OEW) Rational Application Developer Roaster Scriptum Servoy SNiFF+ Sun Java Studio Creator (superseded by NetBeans) Teikade Visual Age (superseded by Eclipse) Visual Café (aka Espresso, superseded by JBuilder) Visual J++ WinGen for Java Servoy Xelfi (became NetBeans) XWPE .NET Compilr MonoDevelop SharpDevelop Visual Studio Express

The newer c++ IDE's will have a compiler that will work
I use qt creator and geany (both work for c++ console applications).
And a lot of people use visual studio, dev c++ and code::blocks

http://www.cplusplus.com/forum/beginner/78825/

You can also check out this link
http://en.wikipedia.org/wiki/List_of_compilers

after you found an ide/compiler to use try doing FSchwartz solution and if they work then try and run your program again.
Last edited on
@FSchwartz program is runing in this Compiler ..
Last edited on
The newest version of the language standard is ISO/IEC 14882-2011 (2012).

The newest version of Microsoft's free compilers is Visual Studio Express 2012.

According to the www.gnu.org web site, the newest version of the gcc compiler collection is 4.6.4. However, if I were installing of the GNU GCC compilers, I would find someone who has created a convenient installation package for my computer's operating system. Other people will have to tell us the versions of g++ they are using.

Other people can tell you the newest versions of other compilers that they are using.

The wikipedia article on Borland C++ shows the evolution of the products that started with Borland products and now are sold by Embarcadero.

Edit: I get the impression that you think there is one C++ compiler. From Bjarne Stroustrup's (original developer of C++), he has a page with an incomplete list of C++ compilers. http://www.stroustrup.com/compilers.html

Last edited on
@FSchwartz I believe number two is supposed to be std::cout

@giblit: True if the C++ language version has "namespace". But if there was a version of C++ without namespaces, then std which is a namespace is not required. Now that I think about it, I would expect only one of 2) or 3) to compile without error, but not both.

I do not have much more to say in this thread since I have very little experience with C++. But for most of the things I have commented on, one does not need to know much C++.

Edit: I just checked the 1998 version of the C++ language standard. Both namespace and <iostream> header are defined there. So if program number 3) does not work, then there is a real problem in naz's environment.
Last edited on
@naz: So, if you put program 3) in a file with the extension .cpp, does it compile without error in your system?
Last edited on
@FSchwartz Showing no Error But Not RuninG
@naz: OK. The execution window may open and close fast, you may not see it. For future, you may want to look at the thread in the Beginner area titled Console Closing Down.

But for now, please try to compile your program from much earlier in the thread. The one where you were getting the error "iostream: No file or directory" on the first line. Since program 3) worked with #include <iostream>, your program should work at least for that line. If it does not, we need to figure out what is different.

Last edited on
@naz: Since we are close to solving your fundamental problem, I looked at your calculation code.

In your original post, you were trying to calculate the slope. As keskiverto pointed out, your slope calculation (a division) uses integer arithmatic. So if your input was 1 1 3 2, your slope calculation would result in (2-1)/(3-1)==(1/2)==0. This is because 2 goes into 1 0 times with a remainder of 1. You could cast one of the variables to double or float. You would have to use the appropriate C++ cast. I am not sure which one that is but I would guess static_cast<double>. TheIdeasMan and giblit warn you that if slope is a double or float, you have to deal with the "approximation" issues of doubles and floats.

As pointed out by keskiverto in his first post, if there is no change in X (dx==0), there will be a division by zero error.

But as giblit points out in his first message and confirmed by keskiverto, you do not need to calculate the slope. You could just look at the differences (deltas) dx and dy. In fact, your problem statement does not require displaying the slope. Given the problems listed above not calculating the slope would be a good approach for you with your level of experience.

As pointed out by cire, your problem statement is misleading. There are two values of slope that are at a 45 degree angle to the x-axis: 1 and -1. As pointed out by keskiverto, this could be handled by using the absolute value function [abs()]. But if you are not comfortable yet using functions, we could handle this by additional cases in the if statements. That would complicate the six cases listed by keskiverto. I think it makes them at least 9 cases.

Or you could just calculate the absolute value directly. For example,

 1234567891011 int dx; int absodx; ... if (dx<0) { absodx = -dx; } else { absodx = dx; }

Now absodx is the absolute value of dx.

Also as keskiverto points out in his first message, you would be better to use an if ... else if ... else if ... else type chain. Have you ever seen code like this? This has the advantage that if your at the third or fourth else if, you know all the if conditions above it are false.

keskiverto points out latter that you need to deal with the case where dx and dx are both zero. Your assignment does not define what you are supposed to display for that case. For example with the input 3 3 3 3, what should be output? You may want add a message about both points being the same.

So to summarize,
1) remove the slope calculation,
2) use the dx and dy and possibly their absolute values for making the decisions,
3) make sure to handle cases with negative slopes,
4) consider using a if ... else if ... else if ... else chain for simplifying you decisions.

To get you started:

 12345678910111213141516171819202122 if ( (dx==0) && (dy==0) ) { cout<<"Both points are the same"<

I hope this helps. In the future, pay close attention to the input you receive. If you do not understand it, ask questions about what they said.
Last edited on
Thankx for help Me to All <3 LOVE U ALL <3
 123456789101112131415161718192021222324252627 #include main() { int slope,X1, Y1, X2, Y2, dy, dx; cout<<"Enter the X-coordinate of the starting point"; cin>>X1; cout<<"Enter the Y-coordinate of the starting point"; cin>>Y1; cout<<"Enter the X-coordinate of the ending point"; cin>>X2; cout<<"Enter the Y-coordinate of the ending point"; cin>>Y2; dy = Y2 - Y1; dx = X2 - X1; slope = dy/dx; if (slope < 1) cout<<"Line will travel more along X-Axis and Less along Y-Axis"; if (slope == 1) cout<<"Line will make the 45 degree angle with the horizon"; if (slope > 1) cout<<"Line will travel more along Y-Axis and Less along X-Axis"; if (dx == 0) cout<<" Line is parallel to Y-Axis"; if (dy == 0) cout<<" Line is parallel to X-Axis"; geth(); }

 1234567891011121314 if ( resultSlope==1 ) { cout<< "Line will make the 45 degree angle with the horizon"<< endl; } else if ( resultSlope < 1 ) { cout<< "Line wil travel more along X-axis & less along Y-axis"<< endl; } else if ( resultSlope > 1 ) cout<< "Line wil travel more along Y-axis & less along X-axis"<< endl; cout<<"Press any Key to continue...." ; getch(); }
Last edited on
 123456789101112131415161718192021222324252627282930313233343536 #include #include using namespace std; main() // main part of the program { int slope; int X1; int Y1; int X2; int Y2; int dy; int dx; cout<<"Enter the X-coordinate of the starting point"; cin>>X1; cout<<"Enter the Y-coordinate of the starting point"; cin>>Y1; cout<<"Enter the X-coordinate of the ending point"; cin>>X2; cout<<"Enter the Y-coordinate of the ending point"; cin>>Y2; //Formula Section dy = Y2 - Y1; dx = X2 - X1; slope = dy/dx; if (slope < 1) cout<<"Line will travel more along X-Axis and Less along Y-Axis"; if (slope == 1) cout<<"Line will make the 45 degree angle with the horizon"; if (slope > 1) cout<<"Line will travel more along Y-Axis and Less along X-Axis"; if (dx == 0) cout<<" Line is parallel to Y-Axis"; if (dy == 0) cout<<" Line is parallel to X-Axis"; }
Last edited on
Pages: 1234