summaryrefslogtreecommitdiff
path: root/Homework/cs5300/homework-one/hw-ch1-src/hw-ch1-src.tex
blob: 7a1eed3df65e351abac78c612da039172a6d316e (plain) (blame)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
\documentclass{article}

\input{common}

\renewcommand{\tt}[1]{\texttt{#1}}
\newcommand{\kc}{$^*$}
\renewcommand{\not}{$^\wedge$}
\newcommand{\pc}{$^+$}
\newcommand{\e}{$\epsilon$}

\includeversion{version:soln}

\begin{document}

\begin{flushleft}
Homework - Chapter 1 \\
CS 5300 %\\

\end{flushleft}

\begin{enumerate}
\item (6 points) What is the difference between a compiler and an interpreter?
  \begin{version:soln}
    \soln Put your solution here.
  \end{version:soln}
  
\myspace
\item (6 points) According to the book, what are the advantages of
  \begin{tightenumerate}
    \item a compiler over an interpreter?
    \item an interpreter over a compiler?
  \end{tightenumerate}
  \begin{version:soln}
    \soln 
  \end{version:soln}

\myspace
\item (6 points) Discuss the portability across computers of compiled vs. interpreted programs.
  \begin{version:soln}
    \soln 
  \end{version:soln}

\myspace
\item (6 points) Strictly speaking, Java is an interpreted language. Discuss how it has elements of being a compiled language.
  \begin{version:soln}
    \soln 
  \end{version:soln}

\myspace
\item (6 points) The C compiler \textit{gcc} has an \tt{-S} option that will output assembly code before the assembler is run. Why might someone want to do this? Give at least two reasons.
  \begin{version:soln}
    \soln 
  \end{version:soln}

\myspace
\item (6 points) If id2 has a value of 8 and id3 has a value of 12, after running the following code, what will be in registers R1 and R2?
\begin{lstlisting}
LDF R1, id2
LDF R2, id3
ADDF R1, R1, R2
\end{lstlisting}
  \begin{version:soln}
    \soln 
  \end{version:soln}

\myspace
\item (6 points) The assembler will fail on this assembly code. Why?
\begin{lstlisting}
LDF R1, id2
LDF R2, id3
ADDF R1, id2, R2
\end{lstlisting}
  \begin{version:soln}
    \soln 
  \end{version:soln}

\myspace
\item (6 points) If id5 is 2 and id7 is 9, what will be in id3 after running this code?
\begin{lstlisting}
LDF R1, id7
LDF R2, id5
ADDF R1, R1, R2
MULF R1, R2, #3.0
STF id3, R1
\end{lstlisting}
  \begin{version:soln}
    \soln 
  \end{version:soln}

\myspace
\item (6 points) Which of the following terms apply to Javascript? Which apply to Python? \\
a)~imperative b)~declarative c)~von Neumann d)~object-oriented e)~third-generation f)~fourth-generation g)~scripting
  \begin{version:soln}
    \soln
  \end{version:soln}

\myspace
\item (5 points) C is not considered an object-oriented language, yet it has structs, which are kind of like objects. Why is it not object-oriented?
  \begin{version:soln}
    \soln 
  \end{version:soln}

\myspace
\item (6 points) Give three examples of programs for which optimization that changes the behavior of the program would be very, very bad.
  \begin{version:soln}
    \soln 
  \end{version:soln}

\myspace
\item (5 points) Give an example of a program for which optimization that changes the behavior of the program might not be so bad.
  \begin{version:soln}
    \soln 
  \end{version:soln}

\myspace
\item (8 points) Given the following blocks in a C++ program, create a table like figure 1.11 in the textbook.

\includegraphics[width=.4\textwidth]{blocks.pdf}

\begin{tabular}{c|c}
\toprule
Declaration & Scope \\
\midrule
\tt{int b = 1;} & \\
\tt{int a = 2;} & \\
\tt{int b = 2;} & \\
\tt{int b = 3;} & \\
\tt{int a = 4;} & \\
\tt{int b = 4;} & \\
\tt{int a = 5;} & \\
\bottomrule
\end{tabular}
  \begin{version:soln}
    \soln 
  \end{version:soln}

\myspace
%\newpage
\item (8 points) For the following block-structured C code, indicate the values assigned to $w, x, y,$ and $z$.
\begin{lstlisting}[language=C]
int w, x, y, z;
int i = 5;
int j = 8;
{ int i = 4;
  j = 9;
  w = j - i;
}
x = j - i;
{ int j = 10;
  y = j - i;
  i = 3;
}
z = j - i;
\end{lstlisting}
  \begin{version:soln}
    \soln 
  \end{version:soln}

\myspace
\newpage
\item (8 points) For the following block-structured C code, indicate the values assigned to $w, x, y,$ and $z$.
\begin{lstlisting}[language=C]
int w, x, y, z;
int i = 2;
int j = 5;
{ int i = 3;
  w = i + j;
}
x = i + j;
{ int j = 9;
  i = 7;
  y = i + j;
  { i = 6;
  }
}
z = i + j;
\end{lstlisting}
  \begin{version:soln}
    \soln 
  \end{version:soln}

\myspace
\item (6 points) What is printed by the following C code?
\begin{lstlisting}[language=C]
#define a (x+3)
int x = 4;
void b() { x = a-1; printf("%d,", x); }
void c() { int x = 1; printf("%d\n", a); }
void main() { b(); c(); }
\end{lstlisting}
  \begin{version:soln}
    \soln 
  \end{version:soln}

\end{enumerate}
\end{document}