{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a1eb1e46",
   "metadata": {},
   "source": [
    "# Chapter Review\n",
    "\n",
    "- Prepare this assignment using a Word document.\n",
    "- Write answers under each question.\n",
    "- Paste code screenshots when required.\n",
    "\n",
    "01. Write the method definition for a static method called\n",
    "    `Q1` which has two `int` parameters, `x` and `y`, and returns a `double`.\n",
    "\n",
    "02. The method above must have what kind of statement in its body?\n",
    "    (see [Statements](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/statements#types-of-statements) for a\n",
    "    formal description of different types of statements for a formal answer or\n",
    "    just use what you have learned so far to answer this question.)\n",
    "\n",
    "03. Each of these lines below has a call to the method above, `Q1`. Which\n",
    "    are legal? Explain:\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "    double d = Q1(2, 5);\n",
    "\n",
    "    int x = Q1(2, 5);\n",
    "\n",
    "    double y = Q1(2) + 5.5;\n",
    "\n",
    "    Console.WriteLine(Q1(\"2\", \"5\"));\n",
    "\n",
    "    Console.WriteLine(Q1(2.5, 5.5));\n",
    "\n",
    "    Q1(10, 20);\n"
   ],
   "id": "e35a4278"
  },
  {
   "cell_type": "markdown",
   "id": "b87cb197",
   "metadata": {},
   "source": [
    "\n",
    "04. Suppose `Q1` does nothing except produce the value to return, like\n",
    "    most methods returning a `double`. Which\n",
    "    line in the previous problem is legal (does not produce error), but has *no* effect?\n",
    "\n",
    "05. Write the method header for a static method called\n",
    "    `Q4` which\n",
    "    has one `string` parameter, `s`, and returns nothing.\n",
    "\n",
    "06. Which of these lines with a call to the method above, `Q4`,\n",
    "    is legal? Explain:\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "    Q4(\"hi\");\n",
    "\n",
    "    string t = Q4(\"hi\");\n",
    "\n",
    "    Console.WriteLine(Q4(\"hi\"));\n",
    "\n",
    "    Q4(\"hi\" + \"ho\");\n",
    "\n",
    "    Q4(\"hi\", \"ho\");\n",
    "\n",
    "    Q4(2);\n"
   ],
   "id": "a00ee2af"
  },
  {
   "cell_type": "markdown",
   "id": "5edac8f0",
   "metadata": {},
   "source": [
    "\n",
    "07. Can you have more than one function/method in the same\n",
    "    class definition with the same name? Explain why. (Google this one for an answer.\n",
    "    This question will be covered in the future but is directly related to our topic here.)\n",
    "\n",
    "08. What is a function/method signature?\n",
    "    Can you have more than one function/method declared in the same\n",
    "    class definition with the same signature? (Same note as above)\n",
    "\n",
    "09. In each part,\n",
    "    is this a legal program? If so, what is printed? If not, why not?\n",
    "\n",
    "    For the code blocks below, each version uses the same code, except for different\n",
    "    versions of `Main`. Here is the common code with the body of `Main` omitted:\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "    using System;\n",
    "    class Local1\n",
    "    {\n",
    "       static int Q(int a)  // 1\n",
    "       {                    // 2\n",
    "          int x = 3;        // 3\n",
    "          x = x + a;        // 4\n",
    "          return x;         // 5\n",
    "       }                    // 6\n",
    "\n",
    "       static void Main()\n",
    "       {\n",
    "          // see each version\n",
    "       }\n",
    "    }\n"
   ],
   "id": "774a0785"
  },
  {
   "cell_type": "markdown",
   "id": "60f3f000",
   "metadata": {},
   "source": [
    "\n",
    "    1. Insert:\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "       static void Main()\n",
    "       {\n",
    "          Q(5);\n",
    "          Console.WriteLine(x);\n",
    "       }\n"
   ],
   "id": "c1ab9671"
  },
  {
   "cell_type": "markdown",
   "id": "f7cddbef",
   "metadata": {},
   "source": [
    "\n",
    "    2. Insert instead:\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "       static void Main()\n",
    "       {\n",
    "          int x= 1;\n",
    "          Q(5);\n",
    "          Console.WriteLine(x);\n",
    "       }\n"
   ],
   "id": "1ad80c65"
  },
  {
   "cell_type": "markdown",
   "id": "f2317d70",
   "metadata": {},
   "source": [
    "\n",
    "    3. Insert instead:\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "       static void Main()                   // 7\n",
    "       {                                    // 8\n",
    "          int x = 1, y = 2;                 // 9\n",
    "          y = Q(5);                         // 10\n",
    "          Console.WriteLine(x + \" \" + y);   // 11\n",
    "       }                                    // 12\n"
   ],
   "id": "90e5ff7b"
  },
  {
   "cell_type": "markdown",
   "id": "28e00c23",
   "metadata": {},
   "source": [
    "\n",
    "10. In the previous problem consider the common code with part c.\n",
    "    Note the line numbers as comments.\n",
    "\n",
    "    1. In what line(s) is `Q` being defined?\n",
    "    2. In what line(s) is `Q` called?\n",
    "    3. What is the return type of `Q`?\n",
    "    4. What is a formal parameter to `Q`?\n",
    "    5. What is used as an actual parameter to `Q`?\n",
    "    6. What is the scope of the `x` in line 3?\n",
    "    7. What is the scope of the `x` in line 9?"
   ]
  }
 ],
 "metadata": {
  "jupytext": {
   "cell_metadata_filter": "-all",
   "main_language": "python",
   "notebook_metadata_filter": "-all"
  },
  "kernelspec": {
   "display_name": ".NET (C#)",
   "language": "C#",
   "name": ".net-csharp"
  },
  "language_info": {
   "name": "csharp"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
