Please create the Flowchart for this programming problem. <!DOCTYPE html> <html
ID: 3771538 • Letter: P
Question
Please create the Flowchart for this programming problem.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> Going Green Energy</title>
</head>
<body>
<script type="text/javascript">
var noOfMonths = 12;
function goGreenStats() {
var notGreenCost = [12];
var goneGreenCost = [12];
var savings = [12];
var months = ["January", "February", "March ", "April ", "May ", "June ", "July ", "August", "September", "October", "November", "December"];
getCosts(notGreenCost, months, "NOT GREEN");
getCosts(goneGreenCost, months, "GREEN");
var i = 0;
var total = 0;
var diff = 0;
var text = "Month Not Go Green Go Green Savings " ;
for(i = 0; i <noOfMonths; i++) {
diff = notGreenCost[i] - goneGreenCost[i];
total += diff;
text += months[i]+" "+notGreenCost[i]+ " "+goneGreenCost[i]+ " " +diff+ " " ;
}
alert(text);
}
function getCosts(costArr, months, mode) {
var i = 0;
var input = 0;
for(i =0; i < noOfMonths; i++ ) {
input = prompt("Enter "+mode+" energy costs for "+months[i], "");
costArr[i] = input;
}
}
goGreenStats();
</script>
<div id="content"> </div>
</body>
</html>
The pseudocode:
Module main()
//Declare local variables
Declare endProgram = “no”
While endProgram == “no”
Declare Real notGreenCost[12]
Declare Real goneGreenCost[12]
Declare Real savings[12]
Declare String months[12] = “January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”
//function calls
getNotGreen(notGreenCost, months)
getGoneGreen(goneGreenCost, months)
energySaved(notGreenCost, goneGreenCosts, savings)
displayInfo(notGreenCost, goneGreenCosts, savings, months)
Display “Do you want to end the program? Yes or no”
Input endProgram
End While
End Module
Module getNotGreen(Real notGreenCost[], String months[])
Set counter = 0
While counter < 12
Display “Enter NOT GREEN energy costs for”, months[counter]
Input notGreenCosts[counter]
Set counter = counter + 1
End While
End Module
Module getGoneGreen(Real goneGreenCost[], String months[])
Set counter = 0
While counter < 12
Display “Enter GONE GREEN energy costs for”, months[counter]
Input goneGreenCosts[counter]
Set counter = counter + 1
End While
End Module
Module energySaved(Real notGreenCost[], Real goneGreenCost[], Real savings[])
Set counter = 0
While counter < 12
Set savings[counter] = notGreenCost[counter] – goneGreenCost[counter]
Set counter = counter + 1
End While
End Module
Module displayInfo(Real notGreenCost[], Real goneGreenCost[], Real savings[], String months[])
Set counter = 0
While counter < 12
Display “Information for”, months[counter]
Display “Savings $”, savings[counter]
Display “Not Green Costs $”, notGreenCost[counter]
Display “Gone Green Costs $”, goneGreenCost[counter]
End While
End Module
Explanation / Answer
Module main()
//Declare local variables
Declare endProgram = “no”
Declare Real notGreenCost[12]
Declare Real goneGreenCost[12]
Declare Real savings[12]
Declare String months[12] = “January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”
Declare Integer option = 0
While endProgram == “no”
//function calls
If option == 1 Then
getNotGreen(notGreenCost, months)
getGoneGreen(goneGreenCost, months)
energySaved(notGreenCost, goneGreenCosts, savings)
Else If option == 2 Then
displayInfo(notGreenCost, goneGreenCosts, savings, months)
Else If option == 3 Then
writeToFile(months, savings)
Else If option == 4 Then
readFromFile(months, savings)
End If
Display “Do you want to end the program? Yes or no”
Input endProgram
End While
End Module
Module writeToFile(String months[], Real savings[])
Declare outFile AppendMode savingsFile
Open savingsFile “savings1.txt”
Write savingsFile “Savings”
Declare Integer counter = 0
While counter < 12
Write savingsFile months[counter]
Write savingsFile savings[counter]
Set counter = counter + 1
End While
Close savingsFile
End Module
Module readFromFile(String months[], Real savings[])
Declare inFile savingsFile
Open inFile “savings1.txt”
Read savingsFile str1
Display str1
Read savingsFile months
Display months
Read savingsFile savings
Display savings
Close inFile
End Module
Module getNotGreen(Real notGreenCost[], String months[])
Set counter = 0
While counter < 12
Display “Enter NOT GREEN energy costs for”, months[counter]
Input notGreenCosts[counter]
Set counter = counter + 1
End While
End Module
Module getGoneGreen(Real goneGreenCost[], String months[])
Set counter = 0
While counter < 12
Display “Enter GONE GREEN energy costs for”, months[counter]
Input goneGreenCosts[counter]
Set counter = counter + 1
End While
End Module
Module energySaved(Real notGreenCost[], Real goneGreenCost[], Real savings[])
Set counter = 0
While counter < 12
Set savings[counter] = notGreenCost[counter] – goneGreenCost[counter]
Set counter = counter + 1
End While
End Module
Module displayInfo(Real notGreenCost[], Real goneGreenCost[], Real savings[], String months[])
Set counter = 0
While counter < 12
Display “Information for”, months[counter]
Display “Savings $”, savings[counter]
Display “Not Green Costs $”, notGreenCost[counter]
Display “Gone Green Costs $”, goneGreenCost[counter]
End While
End Module
The Pseudocode:
Module main()
//Declare local variables
Declare endProgram = “no”
Declare Real notGreenCost[12]
Declare Real goneGreenCost[12]
Declare Real savings[12]
Declare String months[12] = “January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”
Declare Integer option = 0
While endProgram == “no”
//function calls
If option == 1 Then
getNotGreen(notGreenCost, months)
getGoneGreen(goneGreenCost, months)
energySaved(notGreenCost, goneGreenCosts, savings)
Else If option == 2 Then
displayInfo(notGreenCost, goneGreenCosts, savings, months)
Else If option == 3 Then
writeToFile(months, savings)
Else If option == 4 Then
readFromFile(months, savings)
End If
Display “Do you want to end the program? Yes or no”
Input endProgram
End While
End Module
Module writeToFile(String months[], Real savings[])
Declare outFile AppendMode savingsFile
Open savingsFile “savings1.txt”
Write savingsFile “Savings”
Declare Integer counter = 0
While counter < 12
Write savingsFile months[counter]
Write savingsFile savings[counter]
Set counter = counter + 1
End While
Close savingsFile
End Module
Module readFromFile(String months[], Real savings[])
Declare inFile savingsFile
Open inFile “savings1.txt”
Read savingsFile str1
Display str1
Read savingsFile months
Display months
Read savingsFile savings
Display savings
Close inFile
End Module
Module getNotGreen(Real notGreenCost[], String months[])
Set counter = 0
While counter < 12
Display “Enter NOT GREEN energy costs for”, months[counter]
Input notGreenCosts[counter]
Set counter = counter + 1
End While
End Module
Module getGoneGreen(Real goneGreenCost[], String months[])
Set counter = 0
While counter < 12
Display “Enter GONE GREEN energy costs for”, months[counter]
Input goneGreenCosts[counter]
Set counter = counter + 1
End While
End Module
Module energySaved(Real notGreenCost[], Real goneGreenCost[], Real savings[])
Set counter = 0
While counter < 12
Set savings[counter] = notGreenCost[counter] – goneGreenCost[counter]
Set counter = counter + 1
End While
End Module
Module displayInfo(Real notGreenCost[], Real goneGreenCost[], Real savings[], String months[])
Set counter = 0
While counter < 12
Display “Information for”, months[counter]
Display “Savings $”, savings[counter]
Display “Not Green Costs $”, notGreenCost[counter]
Display “Gone Green Costs $”, goneGreenCost[counter]
End While
End Module
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.