0% found this document useful (0 votes)
2 views3 pages

Java Vs C++ Lecturer Notes

The document compares Java and C++ programming languages focusing on operators, sequence, selection, and iteration with contextual examples from Zimbabwe. It provides specific code snippets for arithmetic, logical operators, and control structures like if-else and loops in both languages. Each section illustrates practical applications relevant to local situations, such as calculating costs and transaction approvals.

Uploaded by

online school
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Java Vs C++ Lecturer Notes

The document compares Java and C++ programming languages focusing on operators, sequence, selection, and iteration with contextual examples from Zimbabwe. It provides specific code snippets for arithmetic, logical operators, and control structures like if-else and loops in both languages. Each section illustrates practical applications relevant to local situations, such as calculating costs and transaction approvals.

Uploaded by

online school
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

LECTURER NOTES: JAVA vs C++

Topic: Operators, Sequence, Selection, and Iteration

Contextual Examples: Zimbabwean Situations

1. OPERATORS
Arithmetic Operators: + - * / %

Example: Calculating ZESA Token Cost

Arithmetic Operator Example


JAVA C++
double tokenPrice = 5.0; #include <iostream>
int units = 4; using namespace std;
double total = tokenPrice * units;
[Link]("Total cost = $" + int main() {
total); double tokenPrice = 5.0;
int units = 4;
double total = tokenPrice * units;
cout << "Total cost = $" << total;
return 0;
}
Logical Operators: && || !

Example: EcoCash Transaction Approval

Logical Operator Example


JAVA C++
if(balance >= amount && pinCorrect){ if(balance >= amount && pinCorrect){
[Link]("Transaction cout << "Transaction Approved";
Approved"); }
}

2. SEQUENCE
Definition: Statements executed step-by-step in order.

Example: Kombi Fare Collection

Sequence Example
JAVA C++
double fare = 1.0; double fare = 1.0;
int passengers = 18; int passengers = 18;
double total = fare * passengers; double total = fare * passengers;
[Link]("Total collected = $" + cout << "Total collected = $" << total;
total);

3. SELECTION
Example: Pass or Fail (ZIMSEC style)

If-Else Example
JAVA C++
if(mark >= 50){ if(mark >= 50){
[Link]("Pass"); cout << "Pass";
}else{ }else{
[Link]("Fail"); cout << "Fail";
} }

4. ITERATION (LOOPS)
Example: Printing Class Register

For Loop Example


JAVA C++
for(int i = 1; i <= 5; i++){ for(int i = 1; i <= 5; i++){
[Link]("Student " + i); cout << "Student " << i << endl;
} }
While Loop Example: Deducting balance until zero

While Loop Example


JAVA C++
while(balance > 0){ while(balance > 0){
balance -= 10; balance -= 10;
} }

You might also like