{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "31ac8df2",
   "metadata": {},
   "source": [
    "# Lab 04\n",
    "\n",
    "- **Note that the course policy is that you should not use generative AI\n",
    "  without authorization. If you are suspected to have used generative AI\n",
    "  and not able to explain/reproduce your work when requested, all your\n",
    "  related assignments throughout the semester will be regraded as 0.**\n",
    "\n",
    "01. Create a dotnet console app project ({ref}`create-project`) in your introcscs directory\n",
    "    called **Chapter04**.\n",
    "02. Use the file Program.cs to code.\n",
    "03. Prepare your code in VS Code.\n",
    "04. The namespace of this project is not important at this point of\n",
    "    time but let us call it *IntroCSCS*.\n",
    "05. The class name of this project is *Chapter04*.\n",
    "06. When executing code, you will only use the Main() method.\n",
    "07. You will prepare methods in the same class to be called from\n",
    "    the Main() method.\n",
    "08. Use a Word document to prepare your assignment.\n",
    "09. Paste your screenshots of your code in VS Code (including namespace and class name) and the results of execution (command prompt and username is part of the execution).\n",
    "10. Number the questions and annotate your answers, when appropriate, to show your understanding.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9666afa5",
   "metadata": {},
   "source": "## Boolean Expressions\n\n- Use `csharprepl` to test the expressions below and write the\n  resulted output after the single-line comments at the right.\n\n- You may copy and paste the code below to VS Code or a Word document to\n  prepare the answers.\n\n- Prepare a screenshot.\n\n"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "  int x = 5;\n",
    "  x;                      //\n",
    "  x == 5;                 //\n",
    "  x == 6;                 //\n",
    "  x;                      //\n",
    "  x != 6;                 //\n",
    "  x = 6;\n",
    "  6 == x;                 //\n",
    "  6 != x;                 //\n",
    "  \"hi\" == \"h\" + \"i\";      //\n",
    "  \"HI\" != \"hi\";           //\n",
    "  string s = \"Hello\";\n",
    "  string t = \"HELLO\";\n",
    "  s == t;                 //\n",
    "  s.ToUpper() == t;       //\n"
   ],
   "id": "cdbca9fa"
  },
  {
   "cell_type": "markdown",
   "id": "942a6662",
   "metadata": {},
   "source": [
    "\n",
    "% Simple ``if`` Exercise\n",
    "\n",
    "% ----------------------\n",
    "\n",
    "% Think of two different inputs you could give that would make the\n",
    "\n",
    "% execution of the code fragment proceed differently. What would happen in\n",
    "\n",
    "% each case? (Assume we have access to the class UIF that prints the\n",
    "\n",
    "% prompt line, intake the value input, and turn the input value into\n",
    "\n",
    "% proper data type.)\n",
    "\n",
    "% - Write your answer to your Word document directly under the question\n",
    "\n",
    "% number (e.g., 4.7.3.a).\n",
    "\n",
    "% a. Consider::\n",
    "\n",
    "% string v = UIF.PromptLine(\"Enter a word: \");\n",
    "\n",
    "% if (v.Length > 3) {\n",
    "\n",
    "% v = v + v;\n",
    "\n",
    "% }\n",
    "\n",
    "% Console.WriteLine(\"Now we have \" + v);\n",
    "\n",
    "% #. Consider::\n",
    "\n",
    "% int x = UIF.PromptInt(\"Enter a integer: \");\n",
    "\n",
    "% Console.Write(\"The magnitude of \" + x + \" is \");\n",
    "\n",
    "% if (x < 0) {\n",
    "\n",
    "% x = -x;\n",
    "\n",
    "% }\n",
    "\n",
    "% Console.WriteLine(x);\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d845226d",
   "metadata": {},
   "source": "## `if-else` Exercise\n\nThink of two different inputs you could give that would make the\nexecution of the code fragment proceed differently. What would happen in\neach case? (Assume we have access to the class UIF that prints the prompt\nline, intake the value input, and turn the input value into proper data type.)\n(Google if you do not know what v.Length means.)\n\n- Write your answer to your Word document directly under the question\n  number (e.g., 4.7.2.b).\n\n1. Consider:\n\n"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "   string v = UIF.PromptLine(\"Enter a word: \");\n",
    "   if (v.Length > 3) {\n",
    "      v = v + v;\n",
    "      Console.WriteLine(\"Now we have \" + v);\n",
    "   }\n",
    "   else {\n",
    "      Console.WriteLine(\"We still have \" + v);\n",
    "   }\n"
   ],
   "id": "b8a55022"
  },
  {
   "cell_type": "markdown",
   "id": "2122eeb9",
   "metadata": {},
   "source": [
    "\n",
    "2. Consider:\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "   int x = UIF.PromptInt(\"Enter a integer: \");\n",
    "   Console.Write(\"The magnitude of \" + x + \" is \");\n",
    "   if (x < 0) {\n",
    "      Console.WriteLine(-x);\n",
    "   }\n",
    "   else {\n",
    "      Console.WriteLine(x);\n",
    "   }\n"
   ],
   "id": "0032d552"
  },
  {
   "cell_type": "markdown",
   "id": "bdbdebc1",
   "metadata": {},
   "source": "## Graduation\n\n- Prepare a method in class Chapter04 called Graduation.\n- Prepare the code in VS Code.\n- Call your method Graduation.\n- Make sure the code runs (`dotnet run`).\n- Screenshot the code and paste it in your Word document.\n\nWrite a method, Graduation(), that prompts students for how\nmany credits they have. Print whether of not they have enough\ncredits for graduation. (At M S&T, a minimum of 120 credit hours\nare required for graduation.)"
  },
  {
   "cell_type": "markdown",
   "id": "c80894df",
   "metadata": {},
   "source": "## Calculate Weekly Wages\n\n- prepare a method in class Chapter04 called CalcWeeklyWages\n- Prepare the code in VS Code.\n- Call your method Graduation.\n- Make sure the code runs (`dotnet run`).\n- Screenshot the code and paste it in your Word document.\n\nGiven a person’s work hours for the week and regular hourly wage,\ncalculate the total pay for the week, taking into account overtime.\nHours worked over 40 are overtime, paid at 1.5 times the normal rate.\nThis is a natural place for a method enclosing the calculation.\n\nThe problem clearly indicates two cases: when no more than 40\nhours are worked or when more than 40 hours are worked. In case\nmore than 40 hours are worked, it is convenient to introduce a\nvariable overtimeHours.\n\nYour code would execute successfully and correctly when the following execution\nis performed in the Main() method of class Chapter04:"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "// Calculate Wages\n",
    "Console.Write(\"Enter hours worked: \");\n",
    "double hours = double.Parse(Console.ReadLine());\n",
    "Console.Write(\"Enter dollars paid per hour: \");\n",
    "double wage = double.Parse(Console.ReadLine());\n",
    "double total = CalcWeeklyWages(hours, wage);\n",
    "Console.WriteLine(\n",
    "   \"Wages for {0} hours at ${1:F2} per hour are ${2:F2}.\",\n",
    "   hours, wage, total);\n"
   ],
   "id": "01752524"
  },
  {
   "cell_type": "markdown",
   "id": "01c07620",
   "metadata": {},
   "source": [
    "\n",
    "Note that:\n",
    "\n",
    "1. Two complete sample code can be found here:\n",
    "\n",
    "   - <https://github.com/mstbit/introcs-csharp-examples/blob/master/wages1/wages1.cs>\n",
    "   - <https://github.com/mstbit/introcs-csharp-examples/blob/master/wages2/wages2.cs>\n",
    "\n",
    "2. When calling from Main(), do not forget to return from the method.\n",
    "\n",
    "3. Suffix `F` means data type `float` and the number followed means decimal\n",
    "   places.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "50d29f94",
   "metadata": {},
   "source": "## Congress Exercise\n\nA person is eligible to be a US Senator who is at least 30 years\nold and has been a US citizen for at least 9 years. Write a program\nCongress() to obtain age and length of citizenship from the user\nand print out if a person is eligible to be a Senator or not.\nA person is eligible to be a US Representative who is at least 25\nyears old and has been a US citizen for at least 7 years.\nElaborate your program Congress() so it obtains age\nand length of citizenship and prints whether a person is eligible\nto be a US Representative only, or is eligible for both offices, or\nis eligible for neither.\n\nThis exercise could be done by making an exhaustive treatment of all\npossible combinations of age and citizenship. Try to avoid that.\n\nCaution: be sure to do exhaustive testing. It is easy to write code\nthat is correct for *some* inputs, but not all.\n\n% Implication Exercise\n\n% ----------------------\n\n% We have introduced C# Boolean operators for AND, OR, and NOT.\n\n% There are other Boolean operators important in logic,\n\n% that are not directly given as a C# operator.\n\n% One example is \"implies\", also expressed\n\n% in a logical if-then statement:  If I am expecting rain, then I am carrying an\n\n% umbrella.  Otherwise put:  \"I am expecting rain\" *implies*\n\n% \"I am carrying an umbrella\". The first part is a Boolean expression called the\n\n% *hypothesis*, and the second part is called the *conclusion*.  In general, when\n\n% A and B are Boolean expressions, \"A implies B\" is also a Boolean expression.\n\n% Just as the truth of a compound Boolean expression like \"A and B\" depends on the\n\n% truth value of the two parts, so with *implies*:\n\n% If you are using good logic, and you start with a true assertion,\n\n% you should only be able to conclude something else true, so it is true that\n\n% \"true implies true\".  If you start with garbage you can use that false statement\n\n% in a logical argument and end up with something either false or true:\n\n% \"false implies false\" and \"false implies true\" are both true. The only thing\n\n% that should not work is to start with something true and conclude\n\n% something false.  If that were the case, logical arguments would be useless,\n\n% so \"true implies false\" is false.  There is no C# operator for \"implies\", but\n\n% you can check all four cases of Boolean values for A and B to see that\n\n% \"A implies B\" is true exactly when \"not A or B\" is true.  We can\n\n% express this in C# as ``!A || B``.\n\n% So here is a silly little exercise illustrating both implication and using\n\n% the C# Boolean operators:  Ask the user whether \"I am expecting rain\" is true.\n\n% (We have the UI function Agree.)  Then check with the user whether\n\n% \"I am carrying an umbrella.\"  Then conclude and print out\n\n% whether the implication \"If I am expecting rain, then I am carrying an\n\n% umbrella.\" is true or not in this situation."
  }
 ],
 "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
}