-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexercise1.tex
64 lines (42 loc) · 1.88 KB
/
exercise1.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
\documentclass[11pt]{article}
\include{packages}
\begin{document}
% ========== Edit your name here
%\author{Your Name}
\title{\coursename~Quiz 1: Due by \DueDate{\coursedate}{9}}
\date{}
\maketitle
\medskip
% ========== Begin answering questions here
\section*{Exercises}
\begin{enumerate}
\item Programming on paper (2 credits): \\
Write the shortest valid C++ program on paper.
\item Interpreting programs (2 credits): \\
What does the program in the following listing do if, when it asks you for input, you type two names (for example, Mike Tiger)? Predict the behavior before running the program, then try it.
\lstinputlisting{code/exercise1-2.cpp}
\end{enumerate}
\section*{Programming exercises}
\begin{enumerate}
\item
Loops (2 credits): \\
Write C++ program that computes for an arbitrary $n$
\begin{itemize}
\item $\sum\limits_{i=1}^n i^2$ using a \lstinline|for| loop (1 credit)
\item $\sum\limits_{i=1}^n f(i)$ with $f(x) = \begin{cases} x, \text{ if } x \text{ is even} \\
-x, \text{else} \end{cases}$ 1 (credit)
\end{itemize}
\item Gaming: (2 credits)\\
Write a guessing game where the user has to guess a secret number. After every guess the program tells the user whether their number was too large or too small. At the end the number of tries needed should be printed. It counts only as one try if they input the same number multiple times consecutively.
\item Taylor Series (2 credits): \\
Write a program that computes the Taylor series for the sin function
$$
sin(x) = \sum\limits_{n=0}^N (-1)^{n} \frac{x^{2n+1}}{(2n+1)!}
$$
for a given $n$. Next, use the \lstinline|std::sin| function of the \lstinline|cmath| header of the C++ standard library to obtain the need $n$ such that your implementation and the C++ standard implementation has the same first 5 digits for a given $x$.
% ========== Continue adding items as needed
\end{enumerate}
\doclicenseThis
\end{document}
\grid
\grid