 www.vustudents.ning.com

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

#include <iostream>
// <stdlib.h> is for system("pause");
#include <stdlib.h>
int main()

{
using namespace std;
/*

Before submitting please change variables and then save against yourname.cpp
This program is written by Ali Raza Marchal
Student of Virtual University of Pakistan
BSCS[Hons] 2nd Semester
e-Mail ID: bc120403456@vu.edu.pk
Join Group Study: Skype ID: alirazamirchal

Question: Write a program to calculate the slope of the line
that is passing through two points and display 5 nature of slopw.

*/

int X1, X2;
int Y1, Y2;

float slope, SlopX, SlopY;

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;

SlopX = (X2 - X1);

SlopY = (Y2 - Y1);

slope = (SlopY) / (SlopX);

if(SlopX == 0){

cout "Line is parallel to Y-Axis" endl;
}

else {

if(SlopY == 0){
cout "Line is parallel to X-Axis" endl;
}

else {
if(slope == 1){
cout "Line will make the 45 degree angle with the horizon" endl;
}

else{

if(slope < 1){
cout "Line will travel more along X-Axis and Less along Y-Axis" endl;
}

else {

if(slope > 1){
cout "Line will travel more along Y-Axis and Less along X-Axis" endl;
}
}
}

}

}
system("pause");
return false;
}

Views: 3229

Replies to This Discussion

#include <iostream>
//<stdlib.h> for system pause;
#include <stdlib.h>

main()
{
//Declaring the variable;
int x1,x2,y1,y2;
float dy,dx,slope;
//Enter the value of satarting and ending point on x-axis and y-axis;
cout"Enter the X-Cordinate of the starting point=";
cin>>x1;
cout"Enter the Y-Cordinate of the starting point=";
cin>>y1;
cout"Enter the X-Cordinate of the ending point=";
cin>>x2;
cout"Enter the Y-Cordinate of the ending point=";
cin>>y2;
//calculate difference b/w x2 and x1;
dx=(x2-x1);
//calculate difference b/w y2 and y1;
dy=(y2-y1);
//calculate slope;
slope=(dy)/(dx);
if(dx==0)
{cout"Line is parallel to Y-Cordinate"endl;
}
else
{if(dy==0)
cout"Line is parallel to X-Corndinate"endl;
}
if(slope>1)
{cout"Line will travel more along Y-Axis and less along X-Axis"endl;
}
else
if(slope<1)
{cout"Line will travel more along X-Axis and Less along Y-Axis"endl;
}
if(slope==1)
{cout"Line will make the 45 degree angle with horizon"endl;
}
system("Pause") ;
}

#include <iostream.h>

main()

{
// Declaring variables for input (x,y) and (x1,y1)
int a,b,c,d;
// Declaring variables for formula dx(x1 - x) and dy(y1 - y)
float m,x,y;

cout "Enter the X - Coordinate of the Starting point = ";
cin>> a;

cout "Enter the Y - Coordinate of the Starting point = ";

cin>> b;

cout "Enter the X - Coordinate of the Ending point   = ";

cin>> c;

cout "Enter the Y - Coordinate of the Ending point   = ";

cin>> d ;
// acording to formula  dx(x1 - x)
x = c-a ;
// show message if the resualt (x1 - x)= 0
if (x==0)
{ cout "Line is parallel to Y - Axis ";
}
else
{
// show message if the resualt (y1 - y)= 0
y = d-b ;
if (y==0)
{ cout "Line is parallel to X - Axis ";
}
else
{
// show message if the resualt (dy/dx )= 1
m = y/x;
if (m==1)
{
cout "Line will make the 45 degree angle with the Horizon ";
}
else
{
// show message if the resualt dy/dx > 1
if (m>1)
{
cout "Line will travel more along Y- Axis And less along X- Axis" ;
}
// show message if the resualt dy/dx < 1
if (m<1)
{
cout "Line will travel more along X- Axis And less along Y- Axis" ;
}
}
}
}
}

#include <iostream.h>

main()

{
// Declaring variables for input (x,y) and (x1,y1)
int a,b,c,d;
// Declaring variables for formula dx(x1 - x) and dy(y1 - y)
float m,x,y;

cout "Enter the X - Coordinate of the Starting point = ";
cin>> a;

cout "Enter the Y - Coordinate of the Starting point = ";

cin>> b;

cout "Enter the X - Coordinate of the Ending point = ";

cin>> c;

cout "Enter the Y - Coordinate of the Ending point = ";

cin>> d ;
// acording to formula dx(x1 - x)
x = c-a ;
// show message if the resualt (x1 - x)= 0
if (x==0)
{ cout "Line is parallel to Y - Axis ";
}
else
{
// show message if the resualt (y1 - y)= 0
y = d-b ;
if (y==0)
{ cout "Line is parallel to X - Axis ";
}
else
{
// show message if the resualt (dy/dx )= 1
m = y/x;
if (m==1)
{
cout "Line will make the 45 degree angle with the Horizon ";
}
else
{
// show message if the resualt dy/dx > 1
if (m>1)
{
cout "Line will travel more along Y- Axis And less along X- Axis" ;
}
// show message if the resualt dy/dx < 1
if (m<1)
{
cout "Line will travel more along X- Axis And less along Y- Axis" ;
}
}
}
}
}

#include <iostream.h>

main()

{
// Declaring variables for input (x,y) and (x1,y1)
int a,b,c,d;
// Declaring variables for formula dx(x1 - x) and dy(y1 - y)
float m,x,y;

cout "Enter the X - Coordinate of the Starting point = ";
cin>> a;

cout "Enter the Y - Coordinate of the Starting point = ";

cin>> b;

cout "Enter the X - Coordinate of the Ending point = ";

cin>> c;

cout "Enter the Y - Coordinate of the Ending point = ";

cin>> d ;
// acording to formula dx(x1 - x)
x = c-a ;
// show message if the resualt (x1 - x)= 0
if (x==0)
{ cout "Line is parallel to Y - Axis ";
}
else

// show message if the resualt (y1 - y)= 0
y = d-b ;
if (y==0)
{ cout "Line is parallel to X - Axis ";
}
else

// show message if the resualt (dy/dx )= 1
m = y/x;
if (m==1)
{
cout "Line will make the 45 degree angle with the Horizon ";
}
else
{
// show message if the resualt dy/dx > 1
if (m>1)
{
cout "Line will travel more along Y- Axis And less along X- Axis" ;
}
// show message if the resualt dy/dx < 1
if (m<1)
{
cout "Line will travel more along X- Axis And less along Y- Axis" ;
}
}
}
}
}

#include <iostream>

main()
{
int a,s,d,f;//declaring  input variables for (y,z) and (y1,z1)
float b,n,m;//declaring variables for formula dx(y1-y)and dy(z1-z)
cout"enter the x-Coordinate of the starting point=";
cin>>a;//
cout"enter the y-Coordinate of the starting point=";
cin>>s;
cout"enter the x-Coordinate of the ending point=";
cin>>d;
cout"enter the y-Coordinate of the ending point=";
cin>>f;
//According to the given formula dx(x2-x1);
n=d-a;
// show message if the result (y1 - y)= 0
if (n==0)
{
cout"Line is Parallel to Y-Axis";
}
else
{
// show message if the result (z1-z)= 0
m=f-s;
if (m==0)
{
cout"Line is Parallel to X-Axis";
}
// show message if the result (dy/dx )< 1
if (b<1)
{cout"Line will travel more along X-axis and Less along Y-axis";
}
b=m/n;
// show message if the result (dy/dx )= 1
if (b==1)
{cout"Line will make 45 degree angle with horizen";
}
else
{
// show message if the result (dy/dx )> 1
if (b>1)
cout"Line will travel more along Y-axis and Less along X-axis";
}
}
}

Assignment No. 01 Spring 2013 CS201

#include <iostream.h>

main()

{
// Declaring variables for input (x,y) and (x1,y1)
int a,b,c,d;
// Declaring variables for formula dx(x1 - x) and dy(y1 - y)
float m,x,y;

cout "Enter the X - Coordinate of the Starting point = ";
cin>> a;

cout "Enter the Y - Coordinate of the Starting point = ";

cin>> b;

cout "Enter the X - Coordinate of the Ending point = ";

cin>> c;

cout "Enter the Y - Coordinate of the Ending point = ";

cin>> d ;
// acording to formula dx(x1 - x)
x = c-a ;
// show message if the resualt (x1 - x)= 0
if (x==0)
{ cout "Line is parallel to Y - Axis ";
}
else

// show message if the resualt (y1 - y)= 0
y = d-b ;
if (y==0)
{ cout "Line is parallel to X - Axis ";
}
else

// show message if the resualt (dy/dx )= 1
m = y/x;
if (m==1)
{
cout "Line will make the 45 degree angle with the Horizon ";
}
else
{
// show message if the resualt dy/dx > 1
if (m>1)
{
cout "Line will travel more along Y- Axis And less along X- Axis" ;
}
// show message if the resualt dy/dx < 1
if (m<1)
{
cout "Line will travel more along X- Axis And less along Y- Axis" ;
}
}
}
}
}

NOTE:

Do not copy paste....otherwise u lose ur Marks...!

Final Solution

Assignment No. 01 Spring 2013 CS201

#include <iostream>
#include <stdlib.h>
int main()

{
using namespace std;

int X1, X2;
int Y1, Y2;

float slope, SlopX, SlopY;

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;

SlopX = (X2 - X1);

SlopY = (Y2 - Y1);

slope = (SlopY) / (SlopX);

if(SlopX == 0){

cout "Line is parallel to Y-Axis" endl;
}

else {

if(SlopY == 0){
cout "Line is parallel to X-Axis" endl;
}

else {
if(slope == 1){
cout "Line will make the 45 degree angle with the horizon" endl;
}

else{

if(slope < 1){
cout "Line will travel more along X-Axis and Less along Y-Axis" endl;
}

else {

if(slope > 1){
cout "Line will travel more along Y-Axis and Less along X-Axis" endl;
}
}
}

}

}
system("pause");
return false;
}

NOTE:

Do not copy paste....otherwise u lose ur Marks...!
Just change Variables  & save this file with ur vu id.

2nd Solution:

Assignment No. 01 Spring 2013 CS201

#include <iostream.h>

main()

{
// Declaring variables for input (x,y) and (x1,y1)
int a,b,c,d;
// Declaring variables for formula dx(x1 - x) and dy(y1 - y)
float m,x,y;

cout "Enter the X - Coordinate of the Starting point = ";
cin>> a;

cout "Enter the Y - Coordinate of the Starting point = ";

cin>> b;

cout "Enter the X - Coordinate of the Ending point   = ";

cin>> c;

cout "Enter the Y - Coordinate of the Ending point   = ";

cin>> d ;
// acording to formula  dx(x1 - x)
x = c-a ;
// show message if the resualt (x1 - x)= 0
if (x==0)
{ cout "Line is parallel to Y - Axis ";
}
else

// show message if the resualt (y1 - y)= 0
y = d-b ;
if (y==0)
{ cout "Line is parallel to X - Axis ";
}
else

{
// show message if the resualt (dy/dx )= 1
m = y/x;
if (m==1)
{
cout "Line will make the 45 degree angle with the Horizon ";
}
else
{
// show message if the resualt dy/dx > 1
if (m>1)
{
cout "Line will travel more along Y- Axis And less along X- Axis" ;
}
// show message if the resualt dy/dx < 1
if (m<1)
{
cout "Line will travel more along X- Axis And less along Y- Axis" ;
}
}
}
}
}

NOTE:

Do not copy paste....otherwise u lose ur Marks...!
Just change Variables  & save this file with ur vu id.

Put 'less than sign' after every cout & "greater than sign" after cin. coz less than & greater than sign are not showing here.

CS201 Assignment No. 1 Solution (100% Correct)) #include <iostream.h>

main()

{
// Declaring variables for input (x,y) and (x1,y1)
int a,b,c,d;
// Declaring variables for formula dx(x1 - x) and dy(y1 - y)
float m,x,y;

cout "Enter the X - Coordinate of the Starting point = ";
cin>> a;

cout "Enter the Y - Coordinate of the Starting point = ";

cin>> b;

cout "Enter the X - Coordinate of the Ending point = ";

cin>> c;

cout "Enter the Y - Coordinate of the Ending point = ";

cin>> d ;
// acording to formula dx(x1 - x)
x = c-a ;
// show message if the resualt (x1 - x)= 0
if (x==0)
{ cout "Line is parallel to Y - Axis ";
}
else
{
// show message if the resualt (y1 - y)= 0
y = d-b ;
if (y==0)
{ cout "Line is parallel to X - Axis ";
}
else
{
// show message if the resualt (dy/dx )= 1
m = y/x;
if (m==1)
{
cout "Line will make the 45 degree angle with the Horizon ";
}
else
{
// show message if the resualt dy/dx > 1
if (m>1)
{
cout "Line will travel more along Y- Axis And less along X- Axis" ;
}
// show message if the resualt dy/dx < 1
if (m<1)
{
cout "Line will travel more along X- Axis And less along Y- Axis" ;
}
}
}
}
}

correct and finnal solution cs201 assignment 1st spring 2013

#include <iostream>
// <stdlib.h> is for system("pause");
#include <stdlib.h>
int main()
{
using namespace std;
/*
Before submitting please change variables and then save against yourname.cpp
This program is written by sonia khizer
Student of Virtual University of Pakistan
MCS 2nd Semester
Question: Write a program to calculate the slope of the line
that is passing through two points and display 5 nature of slopw.

*/

int X1, X2;
int Y1, Y2;

float slope, SlopX, SlopY;

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;

SlopX = (X2 - X1);

SlopY = (Y2 - Y1);

slope = (SlopY) / (SlopX);

if(SlopX == 0){
cout "Line is parallel to Y-Axis" endl;
}

else {

if(SlopY == 0){
cout "Line is parallel to X-Axis" endl;
}

else {
if(slope == 1){
cout "Line will make the 45 degree angle with the horizon" endl;
}

else{

if(slope < 1){
cout "Line will travel more along X-Axis and Less along Y-Axis" endl;
}

else {

if(slope > 1){
cout "Line will travel more along Y-Axis and Less along X-Axis" endl;
}
}
}

}

}
system("pause");
return false;
}

100% working code.

*******************REPLACE cout with cout lessthan lessthan sign ********************

***********************

#include <iostream>
#include <conio.h>

using namespace std;
main()

{
// Declaring variables for input (x,y) and (x1,y1)
int a,b,c,d;
// Declaring variables for formula dx(x1 - x) and dy(y1 - y)
float m,x,y;

cout "Enter the X - Coordinate of the Starting point = ";
cin>> a;

cout "Enter the Y - Coordinate of the Starting point = ";

cin>> b;

cout "Enter the X - Coordinate of the Ending point   = ";

cin>> c;

cout "Enter the Y - Coordinate of the Ending point   = ";

cin>> d ;
// acording to formula  dx(x1 - x)
x = c-a ;
// show message if the resualt (x1 - x)= 0
if (x==0)
cout "Line is parallel to Y - Axis ";

else

// show message if the resualt (y1 - y)= 0
y = d-b ;
if (y==0)
cout "Line is parallel to X - Axis ";

else

// show message if the resualt (dy/dx )= 1
m = y/x;
if (m==1)

cout "Line will make the 45 degree angle with the Horizon ";

else
// show message if the resualt dy/dx > 1
if (m>1)

cout "Line will travel more along Y- Axis And less along X- Axis" ;

// show message if the resualt dy/dx < 1
if (m<1)

cout "Line will travel more along X- Axis And less along Y- Axis" ;
getche();
}