Skip to main content
Noble Desktop Publishing Team/2 min read

Calculating GPA

iOS Development Essentials

Swift

Apple's modern language — type-safe, fast, expressive.

Xcode

The IDE — code editor, simulator, debugger, profiler in one.

UIKit / SwiftUI

Old vs new UI frameworks — SwiftUI is the future.

App Store Distribution

Provisioning, signing, and the review process.

Build Programming Foundations at Noble Desktop

Noble Desktop's Full-Stack Web Development Certificate teaches programming fundamentals that transfer across mobile, web, and desktop development.

Dive into iOS development with this tutorial that covers calculation of averages, use of conditional statements, and writing your own function for GPA calculation.

Topics Covered in This IOS Development Tutorial:

Calculating Averages

Exercise Overview

Using arithmetic operators, we can write an app that does simple math calculations. In the Playground, write a program that calculates the grade point average (GPA) for a student in a school that uses academic quarters (four quarters per school year) and a 4.0 grading scale.

Getting GPA Average

  1. You will need to define four variables, one for each academic quarter. Use any values you’d like for the quarters.

  2. Use arithmetic operators to calculate the average of the four academic quarters and set that to a new variable.

  3. Print out the final GPA for the academic year to the results sidebar.

Conditional Statements

Expand the functionality of the GPA app you created by adding conditional statements to test the following conditions:

  1. If the first and second academic quarter GPA values were above or equal to a B (3.0), print the following statement to your results sidebar: “Good work on your first 2 quarters.”

  2. If the first and second academic quarter GPA values weren’t both above a B, then test to see which academic quarter was the problem.

  3. If the first academic quarter was less than a B (3.0), print: “Sorry, your first quarter needs some review.”

  4. If the second quarter was less than a B, print: “Sorry, your second quarter needs some review.”

  5. If the 3rd or 4th academic quarter are equal to a 4.0, print: “Great work on your last half of the year!”

  6. If neither the 3rd or 4th academic quarters are equal to a 4.0, then print: “Work harder next year and get your grades up.”

  7. Make sure to change the values for the four academic quarter variables as needed to fully test all the functionality above.

Writing Your Own Function

  1. Write a function to calculate your grade point average (GPA).

  2. The function should accept four input parameters, a grade point for each quarter, and return a float.

  3. You should assign your returned value to a constant and print it to your screen.