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()

Last updated

Was this helpful?