C# Problem (1) Create a (simplified) C# class for a bank account object with the
ID: 3823235 • Letter: C
Question
C# Problem
(1) Create a (simplified) C# class for a bank account object with the following 3 properties: account number (int type), customer name(string type), and account balance(double type).
(2) Define an array type as the bank account class to store the 10 bank accounts. Use a "for loop" to generate 10 bank accounts accordingly to the following specification: (a) Each account number is 7 digits with 5 digits random number (from 10000 to 99999) plus 2 check digits. The check digits are the sum of the five digits added together. (b) Use a List <string> to initialize 10 customer names of your choice and randomly assign a name to each account customer name without duplication. (c) Randomly create and assign a balance amount to the account balance property ranging from $100.00 to $5,999.99. (d) Print the 10 account information during your creation of them, one line per account.
(3) Use one of the selection sort, bubble sort, or insertion sort to sort the array of 10 bank account objects into descending order of account balance. You just need to modify one of it to suit the object data type.
(4) Print the 10 account information after they are sorted in descending order of account balance, one line per account. Compute and print the average account balance amount for the 10 accounts.
Explanation / Answer
#Part C
from random import *
NUMBER_OF_STUDENTS = 200
NUMBER_OF_QUESTIONS = 20
NUMBER_OF_CHOICES = 4 # 3 choices is A/B/C, 4 choices is A/B/C/D, 5 is A/B/C/D/E
#Part c1
print ('Part c1')
ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def generate_answers () -> str:
n = NUMBER_OF_CHOICES
ansChoice = ALPHABET[:n]
answer = ''
for i in range(NUMBER_OF_QUESTIONS):
answer += choice(ansChoice)
return answer
ANSWERS = generate_answers ()
print (ANSWERS)
#Part c2
print (' Part c2')
from collections import namedtuple
Student = namedtuple('Student', 'name answers')
def random_students () -> [Student]:
studentList = []
for i in range(NUMBER_OF_STUDENTS):
studentList.append(Student(randrange(99999999), generate_answers ()))
return studentList
print (random_students ())
#Part c3
print (' Part c3')
Student2 = namedtuple('Student2', 'name answers scores total')
def random_students2 () -> [Student]:
studentList = []
for i in range(NUMBER_OF_STUDENTS):
answerStr = generate_answers ()
scoreList = []
for i in range(len(answerStr)):
scoreList.append(int(answerStr[i] == ANSWERS[i]))
studentList.append(Student2(randrange(99999999), answerStr, scoreList, sum(scoreList)))
return studentList
print (random_students2())
print()
def total_score (s: Student2)-> int:
return s.total
studentList = random_students2()
studentList.sort(key =total_score, reverse = True)
for i in range(10):
print (studentList[i])
sums = 0
for i in studentList:
sums += i.total
print ('average: ', '{:.1f}'.format(sums/len(studentList)))
#Part c4
print (' Part c4')
def generate_weighted_student_answer (s: str) -> str:
n = NUMBER_OF_CHOICES
ansChoice = ALPHABET[:n]
for i in range(randrange(n*2)):
ansChoice += s
return choice(ansChoice)
print (generate_weighted_student_answer('C'))
def random_students3 () -> [Student]:
studentList = []
for i in range(NUMBER_OF_STUDENTS):
answerStr = ''
for i in range(NUMBER_OF_QUESTIONS):
answerStr += generate_weighted_student_answer(ANSWERS[i])
scoreList = []
for i in range(len(answerStr)):
scoreList.append(int(answerStr[i] == ANSWERS[i]))
studentList.append(Student2(randrange(99999999), answerStr, scoreList, sum(scoreList)))
return studentList
studentList = random_students3()
studentList.sort(key =total_score, reverse = True)
for i in range(10):
print (studentList[i])
sums = 0
for i in studentList:
sums += i.total
print ('average: ','{:.1f}'.format(sums/len(studentList)))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.