ITP100 Exam 3 (Some answers shared only - only the bigger problems)Q5:Assume arrays created and loaded with datastart maincall displayData(states[], votes[], size)call displayTotalVotes(votes[], size)call mostElectoralVotes(states[], votes[], size)call displayFewer(states[], votes[], size)end mainvoid displayData(string states[], int votes[], int size)for(int i from 0 to size-1)output "State: ", s
...[Show More]
ITP100 Exam 3 (Some answers shared only - only the bigger problems)
Q5:
Assume arrays created and loaded with data
start main
call displayData(states[], votes[], size)
call displayTotalVotes(votes[], size)
call mostElectoralVotes(states[], votes[], size)
call displayFewer(states[], votes[], size)
end main
void displayData(string states[], int votes[], int size)
for(int i from 0 to size-1)
output "State: ", states[i]
output "Votes: ", votes[i]
end for
end displayData
void displayTotalVotes(int votes[], int size)
int total = 0
for(int i from 0 to size-1)
total = total + votes[i]
end for
output "Total votes in all ", total
end displayTotalVotes
void mostElectoralVotes(string states[], int votes[], int size)
int maxVotes = votes[0]
int index
for(int i = 1 to size-1)
if(votes[i] > maxVotes)
index = i
end if
end for
output "State with most electoral votes ", states[index]
end mostElectoralVotes
void displayFewer(string states[], int votes[], int size)
[Show Less]
Access Full Document
Instant download after payment
Card Payments
₿
Crypto Accepted