Thread: CS201 Introduction to Programming Assignment No.1 Solution Spring Semester 2013

1. CS201 Introduction to Programming Assignment No.1 Solution Spring Semester 2013

CS201 Introduction to Programming Assignment No.1 Solution Spring Semester 2013

I have write some code this is not full code i am try to make i think there is if else statement need

#include <iostream>
#include <stdlib.h>
#include <math.h>
// Main Function
int main(){
using namespace std;

int p1,p2;

int y1,y2;

int x1, x2;

float resultSlope;
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;
resultSlope = (y2 - y1) / (x2 - x1);
}

2. Idea Solution :

#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" ;
}
}
}
}
}