Jump to content

GPA Calculator


ragnarok775
 Share

Recommended Posts

This is one of my first submissions, I'm a beginner so bare with my code =P

This is a simple GPA calculator where you can calculate your GPA for up to 7 classes.

You input the amount of credits the class is worth on the left and the Grade on the right, You can put the grade in GPA Number format (4.00, 3.00, etc.) or Letter Grade, (A, B+, B, B-, C+, C, C- etc.)

GPACalc.exe

#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=icon.ico
#AutoIt3Wrapper_Compression=4
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
$button_calc_y = 0
$GUI_height = 0
$GPA = 0
$NumClass = 0
$var = 0
$numcheck = 0
Func ask()
    $NumClass = InputBox("GPA Calculator", "How many classes are you taking? (2-7)", "", "", 220, 120)
    If @error = 1 Then
        Exit
    EndIf
    Call("Check")
    $button_calc_y = (($NumClass - 2) * 25) + 85
    $GUI_height = $button_calc_y + 70
EndFunc
Call("ask")

#include <GUIConstants.au3>

Func Check()
    If $NumClass > 7 Then
        MsgBox(0,"GPA - Error", "Invalid Amount of Classes, must be between 2 and 7")
        Call("ask")
    EndIf
    If $NumClass < 2 Then
        MsgBox(0,"GPA - Error", "Invalid Amount of Classes, must be between 2 and 7")
        Call("ask")
    EndIf
EndFunc

GUICreate("GPA", 240, $GUI_height)
GUISetState (@SW_SHOW)
;-----------------------------------------------------------

GuiCtrlCreateLabel("Credits",55,10)
GuiCtrlCreateLabel("Grade",110,10)
GuiCtrlCreateLabel("Grading Scale",165,$GUI_height/8)
GuiCtrlCreateLabel("A = 4.00",170,($GUI_height/8) + 15)
GuiCtrlCreateLabel("B = 3.00",170,($GUI_height/8) + 30)
GuiCtrlCreateLabel("C = 2.00",170,($GUI_height/8) + 45)
GuiCtrlCreateLabel("D = 1.00",170,($GUI_height/8) + 60)
GuiCtrlCreateLabel("F = 0.00",170,($GUI_height/8) + 75)
GuiCtrlCreateLabel("* Note: Under Grade you can type in a Number",7,($GUI_height - 35))
GuiCtrlCreateLabel("value or Letter Grade, examples: 4.0, B, C+",27,($GUI_height - 20))

$Button_calc = GUICtrlCreateButton ("Calculate",72, $button_calc_y, 60, 20)
    
If $NumClass > 1 Then
    $c1c = GUICtrlCreateInput ("",55, 30,45,20)
    $c1g = GUICtrlCreateInput ("",110, 30,45,20)
    GuiCtrlCreateLabel("Class 1",10,30)

    $c2c = GUICtrlCreateInput ("",55, 55,45,20)
    $c2g = GUICtrlCreateInput ("",110, 55,45,20)
    GuiCtrlCreateLabel("Class 2",10,55)
EndIf

If $NumClass > 2 Then
    $c3c = GUICtrlCreateInput ("",55, 80,45,20)
    $c3g = GUICtrlCreateInput ("",110, 80,45,20)
    GuiCtrlCreateLabel("Class 3",10,80)
EndIf

If $NumClass > 3 Then
    $c4c = GUICtrlCreateInput ("",55, 105,45,20)
    $c4g = GUICtrlCreateInput ("",110, 105,45,20)
    GuiCtrlCreateLabel("Class 4",10,105)
EndIf

If $NumClass > 4 Then
    $c5c = GUICtrlCreateInput ("",55, 130,45,20)
    $c5g = GUICtrlCreateInput ("",110, 130,45,20)
    GuiCtrlCreateLabel("Class 5",10,130)
EndIf

If $NumClass > 5 Then
    $c6c = GUICtrlCreateInput ("",55, 155,45,20)
    $c6g = GUICtrlCreateInput ("",110, 155,45,20)
    GuiCtrlCreateLabel("Class 6",10,155)
EndIf

If $NumClass > 6 Then
    $c7c = GUICtrlCreateInput ("",55, 180,45,20)
    $c7g = GUICtrlCreateInput ("",110, 180,45,20)
    GuiCtrlCreateLabel("Class 7",10,180)
EndIf

Func Calculate()
    If $NumClass > 1 Then
        $c1cF = GUICtrlRead($c1c)
        $c1gF = GUICtrlRead($c1g)
        $var = $c1gF
        Call("LetterCheck")
        If $numcheck = 0 Then
            $c1gF = $var
        EndIf
        $c2cF = GUICtrlRead($c2c)
        $c2gF = GUICtrlRead($c2g)
        $var = $c2gF
        Call("LetterCheck")
        If $numcheck = 0 Then
            $c2gF = $var
        EndIf
        $cct = $c1cF + $c2cF
        $cgt = ($c1cF * $c1gF) + ($c2cF * $c2gF)
    EndIf
    If $NumClass > 2 Then
        $c3cF = GUICtrlRead($c3c)
        $c3gF = GUICtrlRead($c3g)
        $var = $c3gF
        Call("LetterCheck")
        If $numcheck = 0 Then
            $c3gF = $var
        EndIf
        $cct = $cct + $c3cF
        $cgt = $cgt + ($c3cF * $c3gF)
    EndIf
    If $NumClass > 3 Then
        $c4cF = GUICtrlRead($c4c)
        $c4gF = GUICtrlRead($c4g)
        $var = $c4gF
        Call("LetterCheck")
        If $numcheck = 0 Then
            $c4gF = $var
        EndIf
        $cct = $cct + $c4cF
        $cgt = $cgt + ($c4cF * $c4gF)
    EndIf
    If $NumClass > 4 Then
        $c5cF = GUICtrlRead($c5c)
        $c5gF = GUICtrlRead($c5g)
        $var = $c5gF
        Call("LetterCheck")
        If $numcheck = 0 Then
            $c5gF = $var
        EndIf
        $cct = $cct + $c5cF
        $cgt = $cgt + ($c5cF * $c5gF)
    EndIf
    If $NumClass > 5 Then
        $c6cF = GUICtrlRead($c6c)
        $c6gF = GUICtrlRead($c6g)
        $var = $c6gF
        Call("LetterCheck")
        If $numcheck = 0 Then
            $c6gF = $var
        EndIf
        $cct = $cct + $c6cF
        $cgt = $cgt + ($c6cF * $c6gF)
    EndIf
    If $NumClass > 6 Then
        $c7cF = GUICtrlRead($c7c)
        $c7gF = GUICtrlRead($c7g)
        $var = $c7gF
        Call("LetterCheck")
        If $numcheck = 0 Then
            $c7gF = $var
        EndIf
        $cct = $cct + $c7cF
        $cgt = $cgt + ($c7cF * $c7gF)
    EndIf

    $GPA = $cgt/$cct
    $RGPA = Round($GPA, 3)

    MsgBox(0, "GPA Calculator", "Your GPA is: " & $RGPA)
EndFunc

Func LetterCheck()
    $numcheck = IsNumber($var)
    If $numcheck = 1 Then
    Else
        Select
            Case $var = "A"
                $var = 4
            Case $var = "A-"
                $var = 3.75
            Case $var = "B+"
                $var = 3.25
            Case $var = "B"
                $var = 3
            Case $var = "B-"
                $var = 2.75
            Case $var = "C+"
                $var = 2.25
            Case $var = "C"
                $var = 2
            Case $var = "C-"
                $var = 1.75
            Case $var = "D+"
                $var = 1.25
            Case $var = "D"
                $var = 1
            Case $var = "D-"
                $var = .75
            Case $var = "F"
                $var = 0
        EndSelect
    EndIf
EndFunc
;-----------------------------------------------------------
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_calc
            Call("Calculate")
    EndSelect
Wend
Link to comment
Share on other sites

  • 10 years later...

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • Moderators

novajones001,

Welcome to the AutoIt forums.

But did you realise that the post above yours dates from nearly 11 years ago and the OP has not been here for the past 8 years? Please do not necropost in future - especially when criticism is all you have to offer.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

That's what I said:

"I'd love to change the world", by Ten Years After (a British group).

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • Moderators

jchd,

Sorry - I did not recognise the track - I know them more for this one:

I'm Going Home @ Woodstock

Was it really over 50 years ago?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Your bones, veins & [remaining] neurons can tell, just as mine.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...