VUDESK

¤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:

 

  • The assignment is submitted after due date.
  • The submitted assignment does not open or file is corrupt.
  • Assignment is copied(partial or full) from any source (websites, forums, students, etc)

 

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:

 

  • Basic concepts of C/C++ language and Programming
  • Dealing with Data types
  • Conditional statements of C/C++ language
  • Expressions
  • Saving a program
  • Compiling a program
  • Executing the program

 

 

Guidelines:

 

  • Code should be properly indented and well commented.
  • Follow C/C++ rules while writing variable names, function names etc
  • Use only dev-C++ for this assignment.

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.

 

  • 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.

 

Sample run of the program:

Tags: (due, 02, 2013), Assignment, CS201, May, and, date, discussion, no.1, More…solution

Views: 1747

Download Documents

Replies to This Discussion

Advertise Here

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

Download Documents

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

RSS

*Member OF Week*

1. Ahssan K

North York, Toronto, ON, Canada

2. + ((( ♥ Nayab ♥ )))

Abu Dhabi, United Arab Emirates

=======================

Popular Social Events

=======================

+ Member of the Day

+ Member of the Week

+ Member of the Month

+ Member of the Year

+ Miss VU

+ Mr VU

+ Gold Members

+ Vote for Miss VU

+ Vote for Mr VU

+ Members Points Table

+ Profile Points Allocation

+ Competition Corner

+ Our Fans Club

+ Certificate Winners

---------------------------------------

௵ Scholars Of Desk

 Gold Members

 MR VU,S

௵ MISS VU,S

 Members Of Month

 Team Members

 Moderators 

  ADMINS

ʭAdministrationʭ

Senior Admin : Yasmeen

VUDESK Owner : Ismail Shah

DMCA.com

VUDESK GROUPS

© 2014   Created by ʭIsmail Shahʭ.

Badges  |  Report an Issue  |  Terms of Service

-->