Вы находитесь на странице: 1из 8

Topic 1:

Selection Structures and Repetition Statements

Submitted by:

Te, Royce T.

Submitted to:

Mr. Cesar A. Llorente


Instructor

Preliminary Report No. 1

I.

Learning Objectives:
-

II.

Use conditional Statements for decision-making.


Use iterative statements for repeating operations
Use iterative statements for complex computations requiring iterations
Develop algorithms for engineering formulas and applications
Create a program that demonstrates the use of engineering equations

Introduction
This laboratory exercise will focus mostly on the use of engineering formulas and equations, that will
be integrated to a C program. The equations that will be included in this lab report will be mostly from
Analytic Geometry, with the focus on graphical equations that include x, y coordinates and the slope as
the variables for the equations. The reason for the choice of the equations is due to the significance of
graphical analysis for multiple courses in the College of Engineering. The use of this program will be
very applicable in most courses that require graphical analysis or any form of plotting in a coordinates
system.
Some of the formulas and equations that will be present in the code will be for solving the variables
of lines and parabolas, since these are mostly the common graphical formations that are present.

III. Problem Statement


Create a program that,
- shows a formula selection screen that allows the user to select a formula
- the formula selection screen allows the user to quit the program
- the program asks the user what variable in the equation to compute
- variable selection screen allows the user to go back to the formula selection screen
- the program asks values for input variables and computes the selected variable
- Program goes back to variable selection screen. User can select another variable to compute or select
to go back to the formula selection screen
- Note: do not use goto and/or global variables (this rule applies to all succeeding final programs).

IV. Flowchart

V.

Source Code
#include <stdio.h>
#include <stdlib.h>
int main()
{
int menu,syntax;
printf("\n\tFormulas and Equations\n");
printf("\tPlease Input Your Choice\n");
printf("\t 1.) Lines\n");
printf("\t 2.) Parabolas\n");
printf("\t 3.) Exit\n");
scanf("%d", &menu);
if (menu==1)
{
int syntax;
printf("\n\tLine Variables\n");
printf("\t 1.) Slope\n");
printf("\t 2.) Y-Intercept\n");
printf("\t 3.) X-coordinate\n");
printf("\t 4.) Y-coordinate\n");
printf("\t 5.) Exit\n");
scanf("%d", &syntax);
if (syntax==1)
{
float a,b,c,d;
printf("\t Please input the x,y,y-intercept in order\n");
scanf("%d %d %d",&c,&a,&b);
d=(a-b)/c;
printf("\t The slope is %5.2f\n",d);
return main();
}
if (syntax==2)
{
float a,b,c,d;
printf("\t Please input the x,y,slope in order\n");
scanf("%d %d %d",&c,&a,&b);
d=a-b*c;
printf("\t The y-intercept is %5.2f\n",d);
return main();
}
if (syntax==3)
{
float a,b,c,d;
printf("\t Please input the slope,y,y-intercept in order\n");
scanf("%d %d %d",&c,&a,&b);
d=(a-b)/c;
printf("\t The x-coordinate is %5.2f\n",d);

return main();
}
if (syntax==4)
{
float a,b,c,d;
printf("\t Please input the x,slope,y-intercept in order\n");
scanf("%d %d %d",&c,&a,&b);
d=c*a+b;
printf("\t The y-coordinate is %5.2f\n",d);
return 0;
}
if (syntax==5)
return main();
}

if (menu==2)
{
int syntax;
printf("\n\tParabola Variables\n");
printf("\t 1.) Vertex\n");
printf("\t 2.) X-coordinate\n");
printf("\t 3.) Y-coordinate\n");
printf("\t 4.) Exit\n");
scanf("%d", &syntax);
if(syntax==1)
{
float a,c,d,f;
printf("\t Please input the value of b, the value of a\n");
scanf("%d %d",&c,&a);
d=c/(2*a);
f=(d*c)-(d*a);
printf("\t The x coordinate vertex is %5.2f\n",d);
printf("\t The y coordinate vertex is %5.2f\n",f);
return main();
}
if(syntax==2)
{
int a,b,c;
float d;
printf("\t Please input the vertex,y-coordinate in order\n");
scanf("%d %d %d",&c,&a,&b);
d=(c-a)^2-b;
printf("\t The x-coordinate is %5.2f\n",d);
return main();
}
if(syntax==3)
{
int a,b,c;

float d;
printf("\t Please input the vertex,x-coordinate in order\n");
scanf("%d %d %d",&c,&a,&b);
d=(b+c)^2-a;
printf("\t The y-coordintate is %5.2f\n",d);
return main();
}
if(syntax==4)
{
return main();
}
}
if (menu==3)
{
printf("\n\tClosing program\n");
return 0;
}
return main();
}

VI. Screen Shots


Sample Lines Function

Sample Parabolas Function

VII. Results and Discussion


Based on the code that I created I was able to fulfill all of the requirements given in the
problem statement. Out of all the requirements in the problem statement it was the selection of
which variables to solve for that proved to be difficult due to the need to create multiple code
statements to satisfy the different variables that needed to be solved in the equation. Even after
creating the statements, there is also the need to input the manipulated equations based on which
variable is to be solved, but other than this the rest of the problem statement requirements were
easily met with the use of a simple if statement code.
In my code I used the equations of the straight / linear line and parabola as the basis for the
variables and the equations that were used, specifically y=mx+b and y=(x-h) 2-k. When it came to
the output some of the values that came out of the functions initially were always rounded off to
the lower value, so many times the values would come up as zero when the output value is less
than 1; I was able to fix this by placing the variables in float instead of int when declaring it in
the code.

VIII. Conclusion
This lab experiment proved to be challenging but doable with the functions that were available
for use, although more complex functions and operations could not be used in the equations due
to the complexity of the coding needed. All problems encountered with the code like the
rounding wrong, syntax were all resolved with internet resources and past lab manuals from the
prerequisites of the course.

Вам также может понравиться