2nd Semester Program
2nd Semester Program
Chapter 1
Applications:
An information system or collection of programs that handles a major task.
Implementation:
The phase of a Systems Development Life Cycle where the programmers would be assigned
to write specific programs.
Efficiency:
The measure of system resources a program consumes.
Maintainability:
The ease with which a program can be modified by its present or future developers.
Portability:
The range of computer hardware and operating system platforms on which the source
code of a program can be compiled/interpreted and run.
Readability:
The ease with which a human reader can comprehend the purpose, control flow, and
operation of source code.
Reliability:
How often the results of a program are correct.
Robustness:
How well a program anticipates problems due to errors.
Usability:
The ease with which a person can use the program.
Dart is a client-optimized language for developing fast apps on any platform. Its goal is to
offer the most productive programming language for multi-platform development, paired
with a flexible execution runtime platform for app frameworks.
void main() { }
This line declares a function called main(). In short, they are a block of statements that the
computer executes when the function is “called.”
The void indicates that the main() function will not return any value.
calls a function built into Dart named “print,” which will print out any line of text to the
console. A piece of text is known as a string
Chapter 2
2.1 Variables
In our Hello World Fancy program, we did not formally declare1 any of our own variables.
However, variables are a basic building block of programming languages. Do you remember
algebra? Where “x” was a variable that represented a number? Variables in programming
are not too different. A variable is used to represent a value and to hold onto it for future use.
= is used differently in Dart than it is in algebra. As has been mentioned before, = is used in
Dart for assignment (assigning values to variables). In Dart, == is used for equality.
var x = 5;
the next example assigns the string literal "antelope" to the variables animalWord.
3
Index – KGS School Web Design
In the next example, the variable coolWord is assigned the value of the string literal
"antelope" Variables may also have a type. For now, you can think of a type as a way of
insisting that a variable only hold a specific kind of value,although this is not completely
accurate. coolWord is specified to be of type String.
coolWord = "dog";
Types are optional in Dart. However, they are useful when we want to ensure the safety of
some of our variables by enforcing a specific type. Types are also helpful when debugging.
2.2 Operators
Operators are used for doing operations. “What’s an operator?” you say. Well, you already
know one! = is the assignment operator. We’ve been using the = operator to assign the
value on the right of an expression to the variable on the left. Dart comes with arithmetic
operators that work as you would expect.
4
Index – KGS School Web Design
Chapter 3
The statements within the curly braces of an if-statement will only be executed if the
statement inside of its parentheses is true. In this case, “It is hot today.” will only be printed to
the console if the variable temperature holds a value greater than 75. > is an operator for
comparison that means “greater than.” If it’s not hot today, maybe we want to print
something else out.
That statement within the curly braces after the else will always be executed when the
value held by temperature is not greater than 75. It will not be executed when the
temperature is above 75.
Now there are three distinct possibilities. else if enables us to expand the number of
branches in our decision tree. If the temperature is greater than 75, then we will say it is hot.
If the temperature is less than or equal to 75 but greater than 50, then we will say it is mild. If
the temperature is less than or equal to 50, then we will say that it is cold. If you do not
follow, go over it again and think about it in the English terms from this paragraph.
5
Index – KGS School Web Design
Chapter 4
switch (favoriteAnimal) {
case "dog": // if favoriteAnimal is equal to "dog" do the following
print("Bark!");
break; //we need one of these at the end of every case but default
case "cow":
print("Moo!");
break;
case "cat":
print("Meow!");
break;
default:
print("Your animal is a new species to me!");
}
The variable we are comparing is the one in parentheses immediately following the switch-
statement. In this case, it is favoriteAnimal. break statements appear at the end of every
case. Not including one may raise an exception. The default option is a catch all if none of
the other cases matched the value of the variable in question. It does not require a break
statement at its end. It is good practice to always include a default clause. This is mostly for
safety reasons—to deal with unexpected values. switch-statements can work with other
6
Index – KGS School Web Design
types as well. They can also have empty cases that “fall-through” to the next case when
there is a match.
Chapter 5
The while-loop will keep executing the lines between the parentheses until num is no longer
greater than 0. Do you remember the -- operator? Again, it is an operator that subtracts 1
from a number. It is used equivalently to this line of code:
num = num - 1;
This is the same as the last loop, except that in a do-while-loop, the check is at the end of
the loop instead of at the beginning. This doesn’t make a difference for our program, but it
can be useful in situations where you always want the first iteration of the loop to execute,
regardless of whether the comparison evaluates to true or false.
7
Index – KGS School Web Design
4.3 Loops – For Loop
int total = 0;
for (int count = 1; count <= 10; count++) {
total = total + count;
}
print("The sum of the numbers 1 through 10 is: $total");
Again, this loop is the same as our last two. It looks very different, though, doesn’t it? for-
loops are compact and extremely useful. Within the parentheses, you have three
statements. The first is an opportunity to create a variable and set its value (this variable is
only accessible within the for loop if it is declared here). The second is a comparison that
must hold for us to continue the loop. The last is what we want to do at the end of each
iteration of the loop.