Education In Pakistan

Papers, Notes, Books & Help For Students

UPDATED EDUCATIONAL NEWS INTERVIEW HELP FOR ALL JOBS ONLINE BOOKS SCHOLARSHIPS AVAILABLE INTERNSHIP JOBS

Tag: VU Assignment No. 01 Semester: Spring 2013 CS201: Introduction to Programming Solved By VU

VU Assignment No. 01 Semester: Spring 2013 CS201: Introduction to Programming Solved By VU

VU Assignment No. 01 Semester: Spring 2013 CS201: Introduction To Programming Solved By VU

#include <iostream>
using namespace std;

int main()
{
// variable declaration.
float dy, dx, x1, x2, y1, y2;
float slope;

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;

// test for condition when dx i.e. (x2-x1)==0
// if this condition is true program will be terminated after the return 0; statment
// slope will not be calculated just message will be displayed
if((x2-x1)==0)
{
cout<<“Line is parallel to Y Axis”;
system(“PAUSE”);
return 0;
}
else // slope will be calculated and value of slope will be stored in slope variable having data type float
slope=(y2-y1)/(x2-x1);

if(slope==0) // test for condition when value of slope variable is equal to 0
cout<<“Line is parallel to X-Axis.”<<endl;

else if(slope<1) // test for condition when value of slope variable is less than 1
cout<<“Line will travel more along X-Axis and Less along Y-Axis”<<endl;

else if(slope==1) // test for condition when value of slope variable is equal to 1
cout<<“Line will make the 45 degree angle with the horizon”<<endl;

else if(slope>1) // test for condition when value of slope variable is greater than 1
cout<<“Line will travel more along Y-Axis and Less along X-Axis”<<endl;

cout<<“Slope: “<<slope<<endl; // Not required to be printed according to assignment
system(“PAUSE”);
}

VU Assignment No. 01 Semester: Spring 2013 CS201: Introduction To Programming Solved By VU

Education In Pakistan © 2016