✒️
Computer Science Principles
  • Introduction
  • Overview
  • Course at a Glance
  • Course Exam Description
  • Create Performance Task
  • Reference Sheet
  • Resources
  • Big Idea 1
    • 1.1 Collaboration
    • 1.2 Program Function and Purpose
    • 1.3 Program Design and Development
    • 1.4 Identifying and Correcting Errors
  • Big Idea 2
    • 2.1 Binary Numbers
    • 2.2 Data Compression
    • 2.3 Extracting Information from Data
    • 2.4 Using Programs with Data
  • Big Idea 3
    • 3.1 Variables and Assignments
    • 3.2 Data Abstraction
    • 3.3 Mathematical Expressions
    • 3.4 Strings
    • 3.5 Boolean Expression
    • 3.6 Conditionals
    • 3.7 Nested Conditionals
    • 3.8 Iteration
    • 3.9 Developing Algorithms
    • 3.10 Lists
    • 3.11 Binary Search
    • 3.12 Calling Procedures
    • 3.13 Developing Procedures
    • 3.14 Libraries
    • 3.15 Random Values
    • 3.16 Simulations
    • 3.17 Algorithmic Efficiency
    • 3.18 Undecidable Problems
  • Big Idea 4
    • 4.1 The Internet
    • 4.2 Fault Tolerant
    • 4.3 Parallel and Distributed Computing
  • Big Idea 5
    • 5.1 Beneficial and Harmful Effects
    • 5.2 Digital Divide
    • 5.3 Computing Bias
    • 5.4 Crowdsourcing
    • 5.5 Legal and Ethical Concerns
    • 5.6 Safe Computing
  • Code
    • Week 10
    • Week 11
    • Week 12
    • Week 13
    • Week 14
    • Week 15
    • Week 16
    • Week 17
    • Week 18
    • Week 19
    • Week 20
    • Week 21
    • Week 22
Powered by GitBook
On this page
  • Source Code
  • w20problem1.lua
  • w20problem2.lua
  • w20problem3.lua
  • w20problem4.lua
  • w20problem5.lua
  • w20problem6.lua
  • w20problem7.lua
  • w20problem8.lua
  • w20problem9.lua
  • project3.lua

Was this helpful?

Export as PDF
  1. Code

Week 20

Source Code

-- define main function
function main()
    print("Main Function")
    local done = false
    local choice = nil
    while not done do
        print("Menu")
        print("E1 - Example 1")
        print("Q - Quit")
        io.write("Choice: ")
        choice = io.read()
        if choice == "E1" then
            -- call Example 1 Function
            example1()

        elseif choice == "E2" then
            example2()

        elseif choice == "E3" then
            example3()

        elseif choice == "E4" then
            example4()

        elseif choice == "E5" then
            example5()

        elseif choice == "Q" then
            done = true
        else
            print("Invalid Choice")
        end
    end
end

-- define Example 1 Function
function example1()
    -- double quotes
    
    -- single quotes
    
    -- \n is a newline
    
    -- Lua multi-line string using double brackets
    

    -- length
    


    -- .upper()
    

    -- .lower()
    

end

-- define Example 2 Function
function example2()
    local major = "Computer Science"
    print(major)

    -- .sub()
    


    -- .find()
    


    -- loop and print every character
    

end

-- define Example 3 Function
function example3()
    -- names list
    

    -- ages list
    


    -- print the names and corresponding ages
    


    -- add a new name and age
    


    -- print the last student's name and age
    


end

-- define Example 4 Function
function example4()
    -- empty list of programming languages
    

    -- add programming languages
    


    -- the number of elements in the dictionary
    

    -- call printDictionary function
    

    -- delete a language
    

    -- add a language
    

    -- call printDictionary function (again)
    


end

-- define Example 5 Function
function example5()
    local csTerms = {
        ["Algorithm"] = "A step-by-step procedure or formula for solving a problem or accomplishing a task.",
        ["API"] = "Application Programming Interface; a set of rules and protocols that allows different software applications to communicate with each other.",
        ["AI"] = "The simulation of human intelligence in machines that are programmed to think and learn like humans.",
        ["Binary"] = "A number system that uses only two digits, 0 and 1, which computers use to process and store data.",
        ["Blockchain"] = "A distributed, immutable ledger technology that records transactions across many computers to ensure data security and transparency.",
        ["Bug"] = "An error, flaw, or fault in a computer program that causes it to produce unexpected results or behave in unintended ways.",
        ["Debugging"] = "The process of finding and resolving defects or problems within a computer program.",
        ["Encryption"] = "The process of converting information or data into a code to prevent unauthorized access.",
        ["Firewall"] = "A network security system that monitors and controls incoming and outgoing network traffic based on predetermined security rules.",
        ["Machine Learning"] = "A subset of AI focused on building systems that learn from data rather than following explicit programming.",
        ["Network"] = "A collection of computers, servers, mainframes, or other devices connected to allow data sharing.",
        ["Open Source"] = "Software whose source code is available for modification or enhancement by anyone.",
        ["URL"] = "Uniform Resource Locator; the address of a resource on the Internet.",
        ["Wi-Fi"] = "A wireless networking technology that allows devices to interface with the Internet or communicate with one another without requiring a wired connection.",
        ["Zero-day"] = "A previously unknown software vulnerability that hackers can exploit before it is patched or mitigated."
    }

    -- access a particular element


    -- update an element


    -- access a particular element


    -- check if key exists


    -- call printDictionary
    


end

-- define dLength Function


-- define printDictionary Function



-- call main function
main()

w20problem1.lua

-- function definition
function problem1()

end

-- function definition
function main()
    -- function call

end

-- call to main function
main()

w20problem2.lua

-- function definition
function problem2()

end

-- function definition
function main()
    -- function call

end

-- call to main function
main()

w20problem3.lua

-- function definition
function problem3()

end

-- function definition
function main()
    -- function call

end

-- call to main function
main()

w20problem4.lua

-- function definition
function problem4()

end

-- function definition
function main()
    -- function call

end

-- call to main function
main()

w20problem5.lua

-- function definition
function problem5()

end

-- function definition
function main()
    -- function call

end

-- call to main function
main()

w20problem6.lua

-- function definition
function problem6()

end

-- function definition
function main()
    -- function call

end

-- call to main function
main()

w20problem7.lua

-- function definition
function problem7()

end

-- function definition
function main()
    -- function call

end

-- call to main function
main()

w20problem8.lua

-- function definition
function problem8()

end

-- function definition
function main()
    -- function call

end

-- call to main function
main()

w20problem9.lua

-- function definition
function problem9()
    local cspTrivia = {}
    cspTrivia["What is binary?"] = "Base-2 number system"
    cspTrivia["What is an algorithm?"] = "Step-by-step procedure for solving a problem"
    cspTrivia["What is abstraction in computing?"] = "Hiding complexity by removing details"
    cspTrivia["What is the difference between the Internet and the World Wide Web?"] = "Internet is the network, Web is content"
    cspTrivia["What is an IP address?"] = "Unique identifier for devices on a network"
    cspTrivia["What is parallel computing?"] = "Multiple processors working simultaneously"
    cspTrivia["What is a Boolean expression?"] = "True or false statement"
    cspTrivia["What is a bit?"] = "0 or 1"
    cspTrivia["What is the purpose of DNS?"] = "Convert domain names to IP addresses"
    cspTrivia["What does HTTP stand for?"] = "HyperText Transfer Protocol"


end

-- function definition
function main()
    -- function call

end

-- call to main function
main()

project3.lua

-- define main function
function main()
    print("Main Function")
    local myOrder = {}
    local done = false
    local choice = nil
    while not done do
        print("Menu")
        print("I - Restaurant Information")
        print("A - Appetizers")
        print("E - Entrees")
        print("B - Beverages")
        print("M - Modify Order")
        print("P - Place Order")
        print("Q - Quit")
        io.write("Choice: ")
        choice = io.read()
        if choice == "Q" then
            print("Quit!")
            done = true
        -- more choices

        else
            print("Invalid Choice")
        end
    end
end

-- define information function

-- define appetizers function

-- define entrees function

-- define desserts function

-- define beverages function

-- define modifyOrder function

-- define placeOrder function


-- call main function
main()

PreviousWeek 19NextWeek 21

Last updated 3 months ago

Was this helpful?