From 2ed3e4a31b5282fd6d92d04e7cb378d0c223d6b5 Mon Sep 17 00:00:00 2001 From: montfortkorir Date: Fri, 22 Mar 2024 14:55:12 +0300 Subject: [PATCH 1/4] Added program 3 --- controlflow.dart | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/controlflow.dart b/controlflow.dart index d6dc466..2b011dd 100644 --- a/controlflow.dart +++ b/controlflow.dart @@ -1,7 +1,35 @@ +// ## Program 3: Determine Grade Based on Marks +// Write a Dart program to determine the grade based on a student's marks. The program should print out the appropriate grade according to the following criteria: +// - If the marks are greater than 85, print "Excellent". +// - If the marks are between 75 and 85 (inclusive), print "Very Good". +// - If the marks are between 65 and 75 (inclusive), print "Good". +// - If the marks are below 65, print "Average". -## Program 3: Determine Grade Based on Marks -Write a Dart program to determine the grade based on a student's marks. The program should print out the appropriate grade according to the following criteria: -- If the marks are greater than 85, print "Excellent". -- If the marks are between 75 and 85 (inclusive), print "Very Good". -- If the marks are between 65 and 75 (inclusive), print "Good". -- If the marks are below 65, print "Average". +import 'dart:io'; + +void main() { + //prompt the user to enter an input + print("\nEnter your marks: \n"); + int? marks = int.parse(stdin.readLineSync()!); + print("\nYour scrore is: ${marks}"); + + /* + check marks between 1 and 100 + and print error message for marks + outside this range + */ + if (marks > 0 && marks <= 100) { + //check the grade + if (marks > 85) { + print("\nExcellent \n"); + } else if (marks > 75) { + print("\nVery Good \n"); + } else if (marks > 65) { + print("\nGood \n"); + } else { + print("\nAverage \n"); + } + } else { + print("\nERROR: Marks cannot be less than 1 or greater than 100. \n"); + } +} From 08094b7c81fe8b3b25f25e33371a6c83105965f7 Mon Sep 17 00:00:00 2001 From: montfortkorir Date: Fri, 22 Mar 2024 15:27:40 +0300 Subject: [PATCH 2/4] Added Program 2 --- functions.dart | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/functions.dart b/functions.dart index 914640c..1c302f3 100644 --- a/functions.dart +++ b/functions.dart @@ -1,2 +1,32 @@ -## Program 2: Perform Mathematical Operations with Functions -Write a Dart program that performs two mathematical operations using functions. +// ## Program 2: Perform Mathematical Operations with Functions +// Write a Dart program that performs two mathematical operations using functions. +import 'dart:io'; + +void main() { + //prompt user to enter the fist number + print("\Enter the 1st number: \n"); + int? any1stNumber = int.parse(stdin.readLineSync()!); + + //prompt user to enter the second number + print("\Enter the 2nd number: \n"); + int? any2ndNumber = int.parse(stdin.readLineSync()!); + + //call the functions that implement the sum and the product + int sum = addTwoNums(any1stNumber, any2ndNumber); + int product = multiplyTwoNums(any1stNumber, any2ndNumber); + + //Print the numbers entered + print("\nYou have entered ${any1stNumber} and ${any2ndNumber}"); + + //print the SUM and the product of the two numbers + print("\nThe sum of ${any1stNumber} and ${any2ndNumber} is ${sum} "); + print("\nThe product of ${any1stNumber} and ${any2ndNumber} is ${product}\n"); +} + +int addTwoNums(num1, num2) { + return (num1 + num2); +} + +int multiplyTwoNums(num1, num2) { + return (num1 * num2); +} From 68f3f6f59fb5c552beb83dcd198093c07ac9f101 Mon Sep 17 00:00:00 2001 From: montfortkorir Date: Fri, 22 Mar 2024 15:39:00 +0300 Subject: [PATCH 3/4] Added Program 1 --- program1.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 program1.dart diff --git a/program1.dart b/program1.dart new file mode 100644 index 0000000..eb90998 --- /dev/null +++ b/program1.dart @@ -0,0 +1,13 @@ +// ## Program 1: Display Personal Information +// Write a Dart program using variables to display your name, age, school, and a hobby. +//Print it in one logical sentence. + +void main() { + String name = "Kipkorir"; + num age = 50; + String school = "PLP"; + String hobby = "Coding"; + + print( + "\nMy name is ${name}, aged ${age}, studying at ${school}. My hobby is ${hobby}.\n"); +} From 63601069a52b09bbfdd0ee4d156e32ffde4a0191 Mon Sep 17 00:00:00 2001 From: montfortkorir Date: Fri, 22 Mar 2024 15:42:43 +0300 Subject: [PATCH 4/4] Added last sentence to README file --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2f9d18e..f5f29ee 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,21 @@ # Dart Programs - - ## Program 1: Display Personal Information + Write a Dart program using variables to display your name, age, school, and a hobby. Print it in one logical sentence. ## Program 2: Perform Mathematical Operations with Functions + Write a Dart program that performs two mathematical operations using functions. ## Program 3: Determine Grade Based on Marks + Write a Dart program to determine the grade based on a student's marks. The program should print out the appropriate grade according to the following criteria: + - If the marks are greater than 85, print "Excellent". - If the marks are between 75 and 85 (inclusive), print "Very Good". - If the marks are between 65 and 75 (inclusive), print "Good". - If the marks are below 65, print "Average". + +All the best.