Question

In: Computer Science

**** Using C Sharp **** ***If possible please include screenshot of output *** **Also, if possible,...

**** Using C Sharp ****

***If possible please include screenshot of output ***

**Also, if possible, please provide info from .txt files created**

You are to write a program which is going to use inheritance. It should start off with the base classes

Account: contains the string name, int accountnumber, double balance.

Savings: Derived from Account class, it should contain double interest rate.

Checkings: Derived from Account class, it should contain double overdraftlimit.

CreditCard: Derived from Checkings class, it should contain int cardnumber.

Create a program which will create an array of 3 Savings accounts, 3 Checkings accounts and 3 CreditCards.
Create 3 files. Savings.txt, Checkings.txt, CreditCards.txt which contains the information for each and infile the information from the file to the array of the classes. *You can come up with own information*

As for the Main, you will get the data from the file to populate the 3 arrays. Then you should simply do a display of all 3 savings, checkings and creditcards in a neat fashion.

Solutions

Expert Solution

CODE:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Derived_Banking
{
// Base Accoutn Class
class Account
{
//Properties
public string Name { get; set; }
public int AccountNumber { get; set; }
public double Balance { get; set; }
}


// Checkings - Inheriting Account's class.
class Checkings : Account
{
//Properties
public double OverDraftLimit { get; set; }
}

// Savings - Inheriting Account's class.
class Savings : Account
{
//Properties
public double InterestRate { get; set; }
}

//Creditcard - Inheriting Account's class.
class Creditcard : Account
{
//Properties
public int CardNumber { get; set; }
}
class Program
{
static void Main(string[] args)
{
// Savings account List(Array)
List<Savings> lstSavings = new List<Savings>();
foreach (KeyValuePair<int, List<string>> item in ReadFiles("Savings.txt"))
{
// check if line content is empty
if (item.Value.Count > 0)
{
//add the respective account obejct to the list intialized before
lstSavings.Add(new Savings
{
Name = item.Value[0],
AccountNumber = Convert.ToInt32(item.Value[1]),
Balance = Convert.ToDouble(item.Value[2]),
InterestRate = Convert.ToDouble(item.Value[3])
});
}
}


Console.WriteLine("Printing value for Savings Account Values -");
// loop through the list of accounts and print them one by one
for (int i = 1; i <= lstSavings.Count(); i++)
{
Print_AccountValues(lstSavings[i - 1], i);
}

// Checkings account List(Array)
List<Checkings> lstCheckings = new List<Checkings>();
foreach (KeyValuePair<int, List<string>> item in ReadFiles("Checkings.txt"))
{
if (item.Value.Count > 0)
{
lstCheckings.Add(new Checkings
{
Name = item.Value[0],
AccountNumber = Convert.ToInt32(item.Value[1]),
Balance = Convert.ToDouble(item.Value[2]),
OverDraftLimit = Convert.ToDouble(item.Value[3])
});
}
}

Console.WriteLine("Printing value for Checkings Account Values -");
// loop through the list of accounts and print them one by one
for (int i = 1; i <= lstCheckings.Count(); i++)
{
Print_AccountValues(lstCheckings[i - 1], i);
}

// Credit Card List(Array)
List<Creditcard> lstCredits = new List<Creditcard>();
foreach (KeyValuePair<int, List<string>> item in ReadFiles("CreditCards.txt"))
{
if (item.Value.Count > 0)
{
lstCredits.Add(new Creditcard
{
Name = item.Value[0],
AccountNumber = Convert.ToInt32(item.Value[1]),
Balance = Convert.ToDouble(item.Value[2]),
CardNumber = Convert.ToInt32(item.Value[3])
});
}
}

Console.WriteLine("Printing value for Credit Card Values -");
// loop through the list of accounts and print them one by one
for (int i = 1; i <= lstCredits.Count(); i++)
{
Print_AccountValues(lstCredits[i - 1], i);
}

Console.ReadLine();
}

// Reads the file line by line and separtes the value in a line using comma(,)
// stores the file content into dictionay of line and line content
// returns the dictionary
static Dictionary<int, List<string>> ReadFiles(string fileName)
{
Dictionary<int, List<string>> tempDict = new Dictionary<int, List<string>>();
//wrap IO operations in try catch block
try
{
int lineCntr = 1;
foreach (string line in File.ReadAllLines(fileName))
{
if (!string.IsNullOrEmpty(line))
tempDict.Add(lineCntr, line.Split(',').ToList());
lineCntr++;
}

return tempDict;
}
catch (Exception ex)
{
throw;
}
}

// Generalized function to print all the properties
// of an object along with its values
static void Print_AccountValues(object obj, int cntr)
{
Console.WriteLine("Printing Values for Counter: " + cntr);
foreach (var item in obj.GetType().GetProperties())
{
Console.WriteLine(item.Name + " : " + item.GetValue(obj, null));
}
}
}
}

Text File Content:

Savings.txt:

Robert Langdon,290558,23467.37,3.50
Mike Dothraki,3190056,2364.90,2.67
Demitri Ghorkawski,1404500,78659008.87,6.76

Checkings.txt:

Robert Manning,45678003,23467.67,10000
Mike Dothraki,31907800,2364.67,34000
Sansa Steward,6780003,12348.67,1300

CreditCards.txt:

John Bolton,31897556,39067.47,4100056
Mike Dothraki,31905956,1045.69,4103056
Arya Stark,4317678,12348.67,51067000

RESULT:


Related Solutions

Please in C++ thank you! Please also include the screenshot of the output. I have included...
Please in C++ thank you! Please also include the screenshot of the output. I have included everything that's needed for this. Pls and thank you! Write a simple class and use it in a vector. Begin by writing a Student class. The public section has the following methods: Student::Student() Constructor. Initializes all data elements: name to empty string(s), numeric variables to 0. bool Student::ReadData(istream& in) Data input. The istream should already be open. Reads the following data, in this order:...
C programming assignment. instructions are given below and please edit this code only. also include screenshot...
C programming assignment. instructions are given below and please edit this code only. also include screenshot of the output //In this assignment, we write code to convert decimal integers into hexadecimal numbers //We pratice using arrays in this assignment #include <stdio.h> #include <stdlib.h> #include <assert.h> //convert the decimal integer d to hexadecimal, the result is stored in hex[] void dec_hex(int d, char hex[]) {    char digits[] ={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',   ...
PLEASE do the following problem in C++ with the screenshot of the output. THANKS! Assuming that...
PLEASE do the following problem in C++ with the screenshot of the output. THANKS! Assuming that a text file named FIRST.TXT contains some text written into it, write a class and a method named vowelwords(), that reads the file FIRST.TXT and creates a new file named SECOND.TXT, to contain only those words from the file FIRST.TXT which start with a lowercase vowel (i.e., with 'a', 'e', 'i', 'o', 'u'). For example, if the file FIRST.TXT contains Carry umbrella and overcoat...
This is C++, please insert screenshot of output please. Part1: Palindrome detector Write a program that...
This is C++, please insert screenshot of output please. Part1: Palindrome detector Write a program that will test if some string is a palindrome Ask the user to enter a string Pass the string to a Boolean function that uses recursion to determine if something is a palindrome or not. The function should return true if the string is a palindrome and false if the string is not a palindrome. Main displays the result ( if the string is a...
C++(screenshot output please) Part 2 - Tree programs Program 1 Implement a tree using an array...
C++(screenshot output please) Part 2 - Tree programs Program 1 Implement a tree using an array Program 2 Implement a tree using linked list - pointer Binary Tree Program 3 - Convert program 1 to a template
Part 1 (Objective C++ and please have output screenshot) The purpose of this part of the...
Part 1 (Objective C++ and please have output screenshot) The purpose of this part of the assignment is to give you practice in creating a class. You will develop a program that creates a class for a book. The main program will simply test this class. The class will have the following data members: A string for the name of the author A string for the book title A long integer for the ISBN The class will have the following...
3. Add mutex locks to tprog2.c to achieve synchronization, and screenshot the output tprog2.c #include <stdio.h>...
3. Add mutex locks to tprog2.c to achieve synchronization, and screenshot the output tprog2.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <pthread.h> void* print_i(void *ptr) { printf("1: I am \n"); sleep(1); printf("in i\n"); } void* print_j(void *ptr) { printf("2: I am \n"); sleep(1); printf("in j\n"); } int main() { pthread_t t1,t2; int rc1 = pthread_create(&t1, NULL, print_i, NULL); int rc2 = pthread_create(&t2, NULL, print_j, NULL); exit(0); }
I want to understand how this can be solved in c++. Please send a screenshot also...
I want to understand how this can be solved in c++. Please send a screenshot also with your code so I can see how it is supposed to be formatted or indented. Instructions: Your program will read in a file of commands. There are three types of commands: Warrior creates a new warrior with the specified name and strength. Battle causes a battle to occur between two warriors. Status lists all warriors, alive or dead, and their strengths. A sample...
Please write in C using linux or unix.please include pictures of the terminal output. Write a...
Please write in C using linux or unix.please include pictures of the terminal output. Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the...
Please complete the following functions using C. ------------------------------------------------------------ #include #include "dynarray.h" /* * This is the...
Please complete the following functions using C. ------------------------------------------------------------ #include #include "dynarray.h" /* * This is the definition of the dynamic array structure you'll use for your * implementation. Importantly, your dynamic array implementation will store * each data element as a void* value. This will permit data of any type to * be stored in your array. Because each individual element will be stored in * your array as type void*, the data array needs to be an array of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT