From 6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6 Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Thu, 2 Jul 2026 11:55:17 -0700 Subject: Init --- .../cs5300/homework-one/hw-ch1-src/hw-ch1-src.tex | 196 +++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 Homework/cs5300/homework-one/hw-ch1-src/hw-ch1-src.tex (limited to 'Homework/cs5300/homework-one/hw-ch1-src/hw-ch1-src.tex') diff --git a/Homework/cs5300/homework-one/hw-ch1-src/hw-ch1-src.tex b/Homework/cs5300/homework-one/hw-ch1-src/hw-ch1-src.tex new file mode 100644 index 0000000..7a1eed3 --- /dev/null +++ b/Homework/cs5300/homework-one/hw-ch1-src/hw-ch1-src.tex @@ -0,0 +1,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} -- cgit v1.3