¤Virtual University Of Pakistan Network¤
Assignment No. 01
Semester: Spring 2013
CS201: Introduction to Programming
Total Marks: 20
Due Date:02/05/2013
Instructions:
Please read the following instructions carefully before submitting assignment. It should be clear that your assignment will not get any credit if:
Note: You have to upload only .cpp file. Assignment in any other format (extension) will not be accepted and will be awarded with zero marks. For example, if you submit code in .doc (Word document) or .txt files or .exe file, no reward will be given in any case.
Objective:
The objective of this assignment is to provide hands on experience of:
Guidelines:
Assignment
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.
Line will make the 45 degree angle with the horizon
Line will travel more along X-Axis and Less along Y-Axis
Line will travel more along Y-Axis and Less along X-Axis
Line is parallel to Y-Axis.
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.
Sample run of the program:
Tags: (due, 02, 2013), Assignment, CS201, May, and, date, discussion, no.1, More…solution
bhai yahaan basically, IF elase ki baat horahi hai
mean ye k condition ko kese define kia jata hai kisi bhi program me
oper safyan bro ne kafi deeply explain kia hai
and i think its enough to understanding.
thank you very much. it is perfect solution
#include
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;
}
one more
#include
#include
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
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" ; } } } } }
well work Amir.
#include <iostream>
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;
}
Thanks all 4 ur coopration
download the attach file for 100% correct solution
sis i also made assignment like this without watching your download but iam confused that the most ending point is "pause" with return false .Is this the correct to end with "Pause".Plz reply honestly.
basically, pause command is uses to hold the program after completely execution
Pl sir define using namespace std;
Yeh code to na to lecture main awar na handout main hai.
awar ais k baghir programme compile nahi ho raha hai.
its a key work to defining the name scope in c++.
its a part of C++, kindly read the book of turbo C (http://vulms.vu.edu.pk/Courses/CS201/Downloads/The%20C%20programmin...)
moon bhai halwa khelate jao sb ko
1 |
Faisal Ali |
2 |
+*ÁŴÁĨŚ*+ |
3 |
Innocent Angel |
4 |
+*PŔĨŃČĔŚŚ*+ |
5 |
Farina |
=======================
Popular Social Events
=======================
+ Miss VU
+ Mr VU
---------------------------------------
௵ MR VU,S
௵ ADMINS
ʭ☀Administration☀ʭ
Senior Admin : Yasmeen
VUDESK Owner : Ismail Shah
© 2014 Created by ʭIsmail Shahʭ.
Awards & Titles |
Chief Admin | Senior Admin | ADMINS | MOTM | Gold Members | Miss VU | MR VU |
VUDESK is social networking website created for the students of Virtual University of Pakistan with an aim of providing educational support in terms of subject oriented material such as Assignment,GDB,Quizes Solutions and of course a light entertainment.
Video Profile
Our Community has also Live TV Transmission to facilitate the students for enhancing their skills as well as to take opportunity for doing something they love to do,Check Below Link To Know all about our upcoming transmission and Programs