Docsity
Docsity

Prepara tus exámenes
Prepara tus exámenes

Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity


Consigue puntos base para descargar
Consigue puntos base para descargar

Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium


Orientación Universidad
Orientación Universidad


Ejercicios Fundamentos de Programación, Ejercicios de Programación Informática

Asignatura: Fundamentos de la Programación, Profesor: Juan Falgueras, Carrera: Grado en Ingeniería Informática, Universidad: UMA

Tipo: Ejercicios

2014/2015

Subido el 23/11/2015

elkappa
elkappa 🇪🇸

4.2

(18)

3 documentos

1 / 3

Toggle sidebar

Esta página no es visible en la vista previa

¡No te pierdas las partes importantes!

bg1
Fundamentals of Programming, ETSII
Pract. 1, Lesson 2-1
1 Introduction to the programming environment. Edit/compile/execute, copying the
given source program, both in a Terminal+Editor and in the Eclipse environments.
Feel free to change the message and the heading comments.
2 The next program computes and display the 2. Change it so it can solve the
equation ax2+bx +c= 0 with x22x3 = 0, using the formula: x1=b+b2
4ac
2a,
x2=bb2
4ac
2a
14/10/14 10:26equs.cpp
gina 1 de 1file:///Users/juanfc/Desktop/equs.cpp.html
// equs.cpp
// juanfc 2014-10-14
// Some maths
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float x = 2;
cout << "The square root of " << x
<< " is: " << sqrt(x) << endl;
return 0;
}
You should ask the user for the three coefficients a, b, c of the ax2+bx +c= 0
equation. These are three real (float) numbers. Then applying the recipe, write on
the screen the resulting values: x1, x2
3 The next C++ program computes the net and gross salaries to be paid for a job done
as a function of the worked days and hours. However, when you try to compile it,
several errors raise. The student should spot those errors and fix them. The compiler
signs and messages should them be interpreted and be followed appropriately.
1# in c l u de <i o s tr e am >
2us in g na me s pa ce s td ;
3
4co ns t ta x : 25 .0 ;
5co ns t HO UR L Y_ PA Y = 60.0
6
7in t main()
pf3

Vista previa parcial del texto

¡Descarga Ejercicios Fundamentos de Programación y más Ejercicios en PDF de Programación Informática solo en Docsity!

Fundamentals of Programming, ETSII

Pract. 1, Lesson 2-

1 Introduction to the programming environment. Edit/compile/execute, copying the

given source program, both in a Terminal+Editor and in the Eclipse environments.

Feel free to change the message and the heading comments.

2 The next program computes and display the

2. Change it so it can solve the

equation ax

+ bx + c = 0 with x

− 2 x − 3 = 0, using the formula: x 1 =

−b+

b^2 − 4 ac 2 a

x 2 =

−b−

b^2 − 4 ac 2 a equs.cpp 14/10/14 10:

// equs.cpp

// juanfc 2014-10-

// Some maths

#include

#include

using namespace std;

int main()

float x = 2 ;

cout << "The square root of " << x

<< " is: " << sqrt(x) << endl;

return 0 ;

You should ask the user for the three coefficients a, b, c of the ax

+ bx + c = 0

equation. These are three real (float) numbers. Then applying the recipe, write on

the screen the resulting values: x 1 , x 2

3 The next C++ program computes the net and gross salaries to be paid for a job done

as a function of the worked days and hours. However, when you try to compile it,

several errors raise. The student should spot those errors and fix them. The compiler

signs and messages should them be interpreted and be followed appropriately.

1 # include < iostream > 2 using namespace std ; 3 4 const tax : 25.0; 5 const HOURLY_PAY = 60. 6 7 int main ()

2

9 double hours , days , total , net ; 10 11 cout << " Enter the number of worked hours : " ; 12 cin << hours ; 13 cout << " Enter the number of worked days : " ; 14 cin >> days ; 15 hours * days * HOURLY_PAY = total ; 16 net = total - TAX ; 17 cout << " The gross amount to be paid is : " ; 18 cout << total << endl ; 19 cout << " The net amount to be paid is : " ; 20 cout << NETO << endl ; 21 22 return 0; 23 }

4 Write a program that allows the input of an integer data type and then it writes it

on the screen. Run this program entering a valid, legal, integer number; run it again

but entering a no valid integer number, any word, for example. Write a comment at

the program source headings explaining the differences between both behaviours.

5 Write a program that display on the screen the size in bytes of every data type

studied in class: int, long, char, etc. Use the operator: sizeof

6 Write a program that reads 4 letters, and then writes those letters but encoded,

writting then, instead of each letter, its next letter in the ASCII table. For example,

if entered SETO, it should print: TFUP.

7 Write a program that reads a natural number, standing for a number of bytes. Then

print the amount of MegaBytes (MB), KiloBytes (KB), and bytes (B) that that

number contains. For example: for the number 26871979, it should print: 25 MB,

642 KB, and 171 B

8 The next program converts an age, entered in years, to days:

1 # include < iostream > 2 using namespace std ; 3 4 int main () 5 { 6 int ageYears ; 7 cout << " Input the age in years : " ; 8 cin >> ageYears ; 9 int ageDays = ageYears * 365; 10 cout << " Days : " << ageDays << endl ; 11 return 0; 12 } 13

Make a program to do the opposite ask for the age in days and display the age in

years (discard the remainded days that not complete a complete year). In order to

ask for a number (or a char or a string... ) we can use in this case:

cin >> age;

In doing so, our program will await there for us to enter a number and that number

will be assigned to the variable age, the only variable we need.

9 A student wants to know their final mark in the subject FP. That mark is built from

the mark in the final exam and the marks in the two tests. The weight of the final

exam mark is wf = 1 − 0. 15 × (m 1 + m 2 )/10. So to obtain the final mark we must

do: mf × wf + (m 1 + m 2 ) × 0 .15.

Ask the user for the final exam, mf , and m 1 and m 2 (all of them over 10), and

display their final mark.