--> Take a copy of the / etc / passwd file to the root user's
home directory.
--> Transfer the username-userID information in this file to the
file named user_idler.txt.
--> Export the file named user_idler.txt in alphabetical order
to user_list.txt file
--> Show how many lines the file user_idler.txt consists
of.
--> Find the number of lines for the letter in the file named
user_idler.txt
In: Computer Science
Create a Python program that:
Save the program and submit it to this site for grading.
In: Computer Science
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile and Execute.
The project is below, I have supplied the code and I'm getting an error in SavingsAccount.h file.
17 5 C:\Users\adam.brunell\Documents\Classes\C++\Week4\SavingsAccount.h [Error] 'SavingsAccount::SavingsAccount(std::string, double, double)' is protected
A.Assume
i.SavingsAccount: Assume an Interest Rate of 0.03
ii.HighInterestSavings: Assume an Interest Rate of 0.05, Minimum Balance = $2500
iii.NoServiceChargeChecking: Assume an Interest Rate = 0.02, Minimum of Balance = $1000
iv.ServiceChargeChecking – Assume account service charge = $10, Maximum number of checks = 5, Service Charge if customer exceeds the maximum number of checks = $5.
v.NoServicechargeChecking: Assume an interest rate = 0.02, Minimum Balance = $1000
vi.HighInterestChecking: Assume an interest rate = 0.05, Minimum Balance = $5000
vii.CertificateOfDepsit: Assume an interest rate = 0.05, Initial Number of Maturity Months = 6
B.Capitalize the first letter of the derived class names.
C.Use the following driver to validate your program:
#include
#include
#include
#include "bankAccount.h"
#include "SavingsAccount.h"
#include "HighInterestSavings.h"
#include "NoServiceChargeChecking.h"
#include "ServiceChargeChecking.h"
#include "HighInterestChecking.h"
#include "CertificateOfDeposit.h"
#include "checkingAccount.h"
using namespace std;
int main()
{
vector accountsList;
//SavingsAccount( Name, Account number, Balance ) - Assume an interest rate = 0.03
accountsList.push_back(new SavingsAccount("Bill", 10200, 2500));
//HighInterestSavings(Name, Account Number, Balance) -- Assume an interest rate = 0.05, Minimum balance = $2500
accountsList.push_back(new HighInterestSavings("Susan", 10210, 2000));
//NoServiceChargeChecking(Name, Account Number, Balance) -- Assume an interest rate = 0.02, Minimum balance = $1000
accountsList.push_back(new NoServiceChargeChecking("John", 20100,
3500));
//ServiceChargeChecking(Name, Account Number, Balance) -- Assume account service charge = $10, Maximum number of checks = 5, Service Charee Excess Number of Checks = $5
accountsList.push_back(new ServiceChargeChecking("Ravi", 30100, 1800));
//HighIntererestChecking(Name, Account Number, Balance) - Assume an inerest rate = 0.05, Minimum balance = $5000
accountsList.push_back(new HighInterestChecking("Sheila", 20200, 6000));
//Certificate(name, Account Number, Balance, Interest Rate, Number of Months) - Assume an initial interest rate = 0.05, Initial Number of Maturity Months = 6
accountsList.push_back(new CertificateOfDeposit("Hamid", 51001, 18000,
0.075, 18));
cout << "January:\n-------------" << endl;
for (int i = 0; i < accountsList.size(); i++)
{
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
cout << endl;
}
cout << "\nFebruary:\n-------------" << endl;
for (int i = 0; i < accountsList.size(); i++)
{
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
cout << endl;
}
for (int i = 0; i < accountsList.size(); i++)
{
accountsList[i]->withdraw(500);
}
cout << "\nMarch:\n-------------" << endl;
for (int i = 0; i < accountsList.size(); i++)
{
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
cout << endl;
}
System(“pause”);
return 0;
}
The Expected Output is:
January:
-------------
Savings account: Bill ACCT# 10200 Balance: $2575.00
High Interest Savings: Susan ACCT# 10210 Balance: $2100.00
No Service Charge Check. John ACCT# 20100 Balance: $3500.00
Service Charge Checking: Ravi ACCT# 30100 Balance: $1790.00
Higher Interest Checking: Sheila ACCT# 20200 Balance: $6300.00
Certificate of Deposit: Hamid ACCT# 51001 Balance: $19350.00
February:
-------------
Savings account: Bill ACCT# 10200 Balance: $2652.25
High Interest Savings: Susan ACCT# 10210 Balance: $2205.00
No Service Charge Check. John ACCT# 20100 Balance: $3500.00
Service Charge Checking: Ravi ACCT# 30100 Balance: $1780.00
Higher Interest Checking: Sheila ACCT# 20200 Balance: $6615.00
Certificate of Deposit: Hamid ACCT# 51001 Balance: $20801.25
March:
-------------
Savings account: Bill ACCT# 10200 Balance: $2216.82
High Interest Savings: Susan ACCT# 10210 Balance: $2315.25
No Service Charge Check. John ACCT# 20100 Balance: $3000.00
Service Charge Checking: Ravi ACCT# 30100 Balance: $1270.00
Higher Interest Checking: Sheila ACCT# 20200 Balance: $6420.75
Certificate of Deposit: Hamid ACCT# 51001 Balance: $22361.34
Press any key to continue . . .
//testdriver.cpp
#include
#include
#include
#include "bankAccount.h"
#include "SavingsAccount.h"
#include "HighInterestSavings.h"
#include "NoServiceChargeChecking.h"
#include "ServiceChargeChecking.h"
#include "HighInterestChecking.h"
#include "CertificateOfDeposit.h"
#include "checkingAccount.h"
using namespace std;
int main()
{
vector accountsList;
//SavingsAccount( Name, Account number, Balance ) -
Assume an interest rate = 0.03
accountsList.push_back(new SavingsAccount("Bill", 10200,
2500));
//HighInterestSavings(Name, Account Number,
Balance) -- Assume an interest rate = 0.05, Minimum balance =
$2500
accountsList.push_back(new HighInterestSavings("Susan", 10210,
2000));
//NoServiceChargeChecking(Name, Account Number,
Balance) -- Assume an interest rate = 0.02, Minimum balance =
$1000
accountsList.push_back(new NoServiceChargeChecking("John",
20100,
3500));
//ServiceChargeChecking(Name, Account Number,
Balance) -- Assume account service charge = $10, Maximum number of
checks = 5, Service Charee Excess Number of Checks = $5
accountsList.push_back(new ServiceChargeChecking("Ravi", 30100,
1800));
//HighIntererestChecking(Name, Account Number,
Balance) - Assume an inerest rate = 0.05, Minimum balance =
$5000
accountsList.push_back(new HighInterestChecking("Sheila", 20200,
6000));
//Certificate(name, Account Number, Balance,
Interest Rate, Number of Months) - Assume an initial interest rate
= 0.05, Initial Number of Maturity Months = 6
accountsList.push_back(new CertificateOfDeposit("Hamid", 51001,
18000,
0.075, 18));
cout << "January:\n-------------" << endl;
for (int i = 0; i < accountsList.size(); i++)
{
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
cout << endl;
}
cout << "\nFebruary:\n-------------" << endl;
for (int i = 0; i < accountsList.size(); i++)
{
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
cout << endl;
}
for (int i = 0; i < accountsList.size(); i++)
{
accountsList[i]->withdraw(500);
}
cout << "\nMarch:\n-------------" << endl;
for (int i = 0; i < accountsList.size(); i++)
{
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
cout << endl;
}
System("pause");
return 0;
}
bankAccount.h
#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H
#include
using namespace std;
class bankAccount {
public:
bankAccount(string name, double initialBalance);
string getName();
unsigned int getAccountNumber();
double getBalance();
double getInterestRate();
string getStatementString();
void deposit(double amount);
void deposit(double amount, string statement);
void withdraw(double amount);
void withdraw(double amount, string statement);
virtual void printStatement() = 0;
protected:
void addStatementLine(string statement, double amount);
private:
string name;
unsigned int accountNumber;
double balance;
static unsigned int nextAccountNumber;
string statementString;
};
#endif /* BANKACCOUNT_H */
//bankAccount.cpp
#include "bankAccount.h"
#include
#include
#include
using namespace std;
unsigned int BankAccount::nextAccountNumber = 1;
BankAccount::BankAccount(string name, double initialBalance)
{
stringstream output;
this->name = name;
balance = initialBalance;
accountNumber = nextAccountNumber++;
output << setw(60) << left << "Transaction"
<< setw(10) << "Amount" << " " << "Balance"
<< endl;
statementString = output.str();
addStatementLine("Initial Deposit", initialBalance);
}
string BankAccount::getName()
{
return name;
}
unsigned int BankAccount::getAccountNumber()
{
return accountNumber;
}
double BankAccount::getBalance()
{
return balance;
}
void BankAccount::addStatementLine(string statement, double
amount)
{
stringstream output;
output << setw(60) << left << statement <<
setw(10) << amount << " " << getBalance()
<< endl;
//.append(statement);
statementString.append(output.str());
}
void BankAccount::deposit(double amount)
{
deposit(amount, "Deposit");
}
void BankAccount::deposit(double amount, string statement)
{
balance += amount;
addStatementLine(statement, amount);
}
void BankAccount::withdraw(double amount)
{
withdraw(amount, "Withdrawal");
}
void BankAccount::withdraw(double amount, string
statement)
{
if (balance >= amount)
{
balance -= amount;
addStatementLine(statement, amount);
}
else
{
addStatementLine(statement.append(" Overdraft"), amount);
}
}
string BankAccount::getStatementString()
{
return statementString;
}
//CertificateOfDeposit.h
#ifndef CERTIFICATEOFDEPOSIT_H
#define CERTIFICATEOFDEPOSIT_H
#include "bankAccount.h"
#include
using namespace std;
class CertificateOfDeposit : public bankAccount{
public:
CertificateOfDeposit(string name, double initialBalance, int
maturityMonths);
CertificateOfDeposit(string name, double initialBalance);
int getMaturityMonths();
double getInterestRate();
int getCurrentCDMonth();
int getWithdrawalPenaltyMonths();
void withdraw();
void incrementMonth();
void printStatement();
private:
int maturityMonths;
double interestRate;
int currentCDMonth;
int withdrawalPenaltyMonths;
void withdraw(double amount);
void withdraw(double amount, string statement);
void deposit(double amount);
};
#endif /* CERTIFICATEOFDEPOSIT_H */
//CertificateOfDeposit.cpp
#include "CertificateOfDeposit.h"
CertificateOfDeposit::CertificateOfDeposit(string name, double
initialBalance, int maturityMonths) : bankAccount(name,
initialBalance)
{
this->maturityMonths = maturityMonths;
interestRate = 0.05;
currentCDMonth = 0;
withdrawalPenaltyMonths = 3;
}
CertificateOfDeposit::CertificateOfDeposit(string name, double
initialBalance) : bankAccount(name, initialBalance)
{
maturityMonths = 6;
interestRate = 0.05;
currentCDMonth = 0;
withdrawalPenaltyMonths = 3;
}
int CertificateOfDeposit::getCurrentCDMonth()
{
return currentCDMonth;
}
double CertificateOfDeposit::getInterestRate()
{
return interestRate;
}
int CertificateOfDeposit::getWithdrawalPenaltyMonths()
{
return withdrawalPenaltyMonths;
}
int CertificateOfDeposit::getMaturityMonths()
{
return maturityMonths;
}
void CertificateOfDeposit::withdraw()
{
if (getCurrentCDMonth() < getMaturityMonths())
bankAccount::withdraw(getBalance()*getInterestRate()*getWithdrawalPenaltyMonths(),
"Early Withdrawal Penalty");
bankAccount::withdraw(getBalance(), "Close Account");
}
void CertificateOfDeposit::incrementMonth()
{
bankAccount::deposit(getBalance()*getInterestRate(), "Monthly
Interest");
if (getCurrentCDMonth() < getMaturityMonths())
{
currentCDMonth++;
}
else
withdraw();
}
void CertificateOfDeposit::printStatement()
{
cout << "Certificate of Deposit Statement" <<
endl;
cout << "Name: " << getName() << endl;
cout << "Account Number: " << getAccountNumber()
<< endl;
cout << "Interest Rate: " << getInterestRate() * 100
<< "%" << endl;
cout << "Maturity Month: " << getMaturityMonths()
<< ", Current Month: " << getCurrentCDMonth() <<
endl;
cout << "Early Withdrawal Penalty: " <<
getWithdrawalPenaltyMonths() << " (months)" << endl
<< endl;
cout << getStatementString() << endl;
cout << "Final Balance: " << getBalance() << endl
<< endl;
}
//HighInterestChecking.h
#ifndef HIGHINTERESTCHECKING_H
#define HIGHINTERESTCHECKING_H
#include "NoServiceChargeChecking.h"
#include
using namespace std;
class HighInterestChecking : public NoServiceChargeChecking
{
public:
HighInterestChecking(string name, double initialBalance);
void printStatement();
private:
};
#endif /* HIGHINTERESTCHECKING_H */
//HighInterestChecking.cpp
#include "HighInterestChecking.h"
HighInterestChecking::HighInterestChecking(string name, double
initialBalance) : NoServiceChargeChecking(name, initialBalance,
5000, 0.05)
{
}
void HighInterestChecking::printStatement()
{
bankAccount::deposit(getBalance() * getInterestRate(),
"Interest");
cout << "High Interest Checking Statement" <<
endl;
cout << "Name: " << getName() << endl;
cout << "Account Number: " << getAccountNumber()
<< endl;
cout << "Interest Rate: " << getInterestRate() * 100
<< "%" << endl;
cout << "Minimum Balance: " << getMinimumBalance()
<< endl << endl;
cout << getStatementString() << endl;
cout << "Final Balance: " << getBalance() << endl
<< endl;
}
//HighInterestSavings.h
#ifndef HIGHINTERESTSAVINGS_H
#define HIGHINTERESTSAVINGS_H
#include "SavingsAccount.h"
#include
using namespace std;
class HighInterestSavings : public SavingsAccount{
public:
HighInterestSavings(string name, double initialBalance);
int getMinimumBalance();
void printStatement();
void withdraw(double amount, string statement);
void withdraw(double amount);
private:
int minimumBalance;
};
#endif /* HIGHINTERESTSAVINGS_H */
//HighInterestSavings.cpp
#include "HighInterestSavings.h"
HighInterestSavings::HighInterestSavings(string name, double
initialBalance) : SavingsAccount(name, initialBalance, 0.05)
{
minimumBalance = 2500;
}
int HighInterestSavings::getMinimumBalance()
{
return minimumBalance;
}
void HighInterestSavings::withdraw(double amount, string
statement)
{
if (amount + getMinimumBalance() <= getBalance())
{
bankAccount::withdraw(amount, statement);
}
else
{
addStatementLine(statement.append(" Overdraft. Below Minimum
Balance."), amount);
}
}
void HighInterestSavings::withdraw(double amount)
{
withdraw(amount, "Withdrawal");
}
void HighInterestSavings::printStatement()
{
bankAccount::deposit(getBalance() * getInterestRate(),
"Interest");
cout << "High Interest Savings Account Statement" <<
endl;
cout << "Name: " << getName() << endl;
cout << "Account Number: " << getAccountNumber()
<< endl;
cout << "Minimum Balance: " << getMinimumBalance()
<< endl;
cout << "Interest Rate: " << getInterestRate() * 100
<< "%" << endl << endl;
cout << getStatementString() << endl;
cout << "Final Balance: " << getBalance() << endl
<< endl;
}
//NoServiceChargeChecking.h
#ifndef NOSERVICECHARGECHECKING_H
#define NOSERVICECHARGECHECKING_H
#include "checkingAccount.h"
#include
using namespace std;
class NoServiceChargeChecking : public CheckingAccount {
public:
NoServiceChargeChecking(string name, double initialBalance);
void writeCheck(double amount, int checkNumber);
void printStatement();
void withdraw(double amount, string statement);
void withdraw(double amount);
double getInterestRate();
int getMinimumBalance();
protected:
NoServiceChargeChecking(string name, double initialBalance, int
minBalance, double interestRate);
private:
double interestRate;
int minimumBalance;
};
#endif /* NOSERVICECHARGECHECKING_H */
//NoServiceChargeChecking.cpp
#include "NoServiceChargeChecking.h"
#include
#include
NoServiceChargeChecking::NoServiceChargeChecking(string name,
double initialBalance) : checkingAccount(name,
initialBalance)
{
minimumBalance = 1000;
this->interestRate = 0.02;
}
NoServiceChargeChecking::NoServiceChargeChecking(string name,
double initialBalance, int minBalance, double interestRate) :
checkingAccount(name, initialBalance)
{
minimumBalance = minBalance;
this->interestRate = interestRate;
}
void NoServiceChargeChecking::writeCheck(double amount, int
checkNumber)
{
stringstream output;
output << "Check #" << checkNumber;
withdraw(amount, output.str());
}
void NoServiceChargeChecking::withdraw(double amount, string
statement)
{
if (amount + getMinimumBalance() <= getBalance())
{
bankAccount::withdraw(amount, statement);
}
else
{
addStatementLine(statement.append(" Overdraft. Below Minimum
Balance."), amount);
}
}
void NoServiceChargeChecking::withdraw(double amount)
{
withdraw(amount, "Withdrawal");
}
void NoServiceChargeChecking::printStatement()
{
bankAccount::deposit(getBalance() * getInterestRate(),
"Interest");
cout << "No Service Charge Checking Statement" <<
endl;
cout << "Name: " << getName() << endl;
cout << "Account Number: " << getAccountNumber()
<< endl;
cout << "Interest Rate: " << getInterestRate() * 100
<< "%" << endl;
cout << "Minimum Balance: " << getMinimumBalance()
<< endl << endl;
cout << getStatementString() << endl;
cout << "Final Balance: " << getBalance() << endl
<< endl;
}
int NoServiceChargeChecking::getMinimumBalance()
{
return minimumBalance;
}
double NoServiceChargeChecking::getInterestRate()
{
return interestRate;
}
//checkingAccount.h
#ifndef CHECKINGACCOUNT_H
#define CHECKINGACCOUNT_H
#include "bankAccount.h"
class CheckingAccount : public bankAccount {
public:
CheckingAccount(string name, double initialBalance);
virtual void writeCheck(double amount, int checkNumber) = 0;
private:
};
#endif /* CHECKINGACCOUNT_H */
//checkingAccount.cpp
#include "checkingAccount.h"
CheckingAccount::CheckingAccount(string name, double
initialBalance) : bankAccount(name, initialBalance)
{
}
//SavingsAccount.h
#ifndef SAVINGSACCOUNT_H
#define SAVINGSACCOUNT_H
#include "bankAccount.h"
#include
#include
using namespace std;
class SavingsAccount : public bankAccount
{
public:
SavingsAccount(string name, double initialBalance);
double getInterestRate();
void printStatement();
protected:
SavingsAccount(string name, double initialBalance, double
interestRate);
private:
double interestRate;
};
#endif /* SAVINGSACCOUNT_H */
//SavingsAccount.cpp
#include "SavingsAccount.h"
SavingsAccount::SavingsAccount(string name, double
initialBalance) : bankAccount(name, initialBalance)
{
interestRate = 0.03;
}
SavingsAccount::SavingsAccount(string name, double
initialBalance, double interestRate) : bankAccount(name,
initialBalance)
{
this->interestRate = interestRate;
}
double SavingsAccount::getInterestRate()
{
return interestRate;
}
void SavingsAccount::printStatement()
{
bankAccount::deposit(getBalance() * getInterestRate(),
"Interest");
cout << "Savings Account Statement" << endl;
cout << "Name: " << getName() << endl;
cout << "Account Number: " << getAccountNumber()
<< endl;
cout << "Interest Rate: " << getInterestRate() * 100
<< "%" << endl << endl;
cout << getStatementString() << endl;
cout << "Final Balance: " << getBalance() << endl
<< endl;
}
//ServiceChargeChecking.h
#ifndef SERVICECHARGECHECKING_H
#define SERVICECHARGECHECKING_H
#include "checkingAccount.h"
#include
using namespace std;
class ServiceChargeChecking : public CheckingAccount {
public:
ServiceChargeChecking(string name, double initialBalance);
void writeCheck(double amount, int checkNumber);
void printStatement();
private:
int checksWritten;
static const int CHECK_LIMIT = 5;
static const int SERVICE_CHARGE = 10;
};
#endif /* SERVICECHARGECHECKING_H */
//ServiceChargeChecking.cpp
#include "ServiceChargeChecking.h"
#include
#include
using namespace std;
ServiceChargeChecking::ServiceChargeChecking(string name, double
initialBalance) : CheckingAccount(name, initialBalance)
{
bankAccount::withdraw(SERVICE_CHARGE, "Service Charge");
checksWritten = 0;
}
void ServiceChargeChecking::writeCheck(double amount, int
checkNumber)
{
stringstream output;
if (++checksWritten <= CHECK_LIMIT)
{
output << "Check #" << checkNumber;
bankAccount::withdraw(amount, output.str());
}
else
{
output << "Maximum Limit of Checks Reached. Check # "
<< checkNumber << " bounced";
addStatementLine(output.str(), amount);
}
}
void ServiceChargeChecking::printStatement()
{
cout << "Service Charge Checking Statement" <<
endl;
cout << "Name: " << getName() << endl;
cout << "Account Number: " << getAccountNumber()
<< endl << endl;
cout << getStatementString() << endl;
cout << "Final Balance: " << getBalance() << endl
<< endl;
}
Receiving Error in SavingsAccount.h
17 5 C:\Users\adam.brunell\Documents\Classes\C++\Week4\SavingsAccount.h [Error] 'SavingsAccount::SavingsAccount(std::string, double, double)' is protected
In: Computer Science
In: Computer Science
use logism: For each of the following functions, simplify using Karnaugh Maps, then build, and hand in a properlydocumented circuit. You need to submit both a K-Map as well as the circuit for each part. a) F1 (a,b,c,d) = Σ(1, 2, 3, 4, 5, 9,10,11) b) F2 (a,b,c,d) = Σ(2, 3, 4, 6, 8, 11, 15) δ(a,b,c,d) = Σ(0, 5, 7, 9, 10)
In: Computer Science
Use the Affine cipher algorithm with k1=7,k2=11 to encrypt the following message : I want to get a hundred in this test
In: Computer Science
What is Enterprise Governance and IT Governance in Enterprise Architecture? PLEASE write in your own words! thanks
In: Computer Science
Write a code in C to shift serially the content of the register labelled x through the bit #1 of Port A starting with least significant bit. Include the port configuration. Do not include any directive.
In: Computer Science
(Do the algorithm and flowchart)
Write a C++ program that reads integer numbers and print it in horizontal order of the screen
In: Computer Science
Python3 *Use Recursion*
Write a function called smallest_sum(A,L) where A is the value and L is a list of ints.
smallest_sum should return the length of the smallest combinations of L that add up to A
if there are no possible combinations then float("inf") is returned.
Examples
smallest_sum(5, [2, 3]) == 2
smallest_sum(313, [7, 24, 42]) == 10
smallest_sum(13, [8, 3, 9, 6]) == float(‘‘inf’’)
No Loops and map/reduce functions are allowed
In: Computer Science
The Gary class is subject to C++ unit testing and therefore has stricter requirements for composition. Each required member function will be denoted. (
1) Gary shall be constructed with a parameterized constructor accepting an unsigned integer input parameter representing the size of the board (denote here as BoardSize). Assume that BoardSize is odd! Gary shall initialize his position to be the middle cell of the board, e.g., if the BoardSize is given as 5 Gary would be initialized at index (2,2).
(2) Gary shall contain public member functions which return an unsigned integer type and accept no input named Gary::get_row() and Gary::get_col() which return Gary's row and column position on the board respectively.
(3) Gary shall contain a public member function which returns type void and accepts a Cell pointer called Gary::move(Cell*) which shall (a) alter Gary's orientation based on the Cell's color (b) change the Cell's color (c) move Gary one unit forward in the new orientation
(4) Gary shall contain a public member function which returns type orientation (defined as an enumeration enum orientation {up, right, down, left};) and accepts no input parameters called Gary::get_orientation()
In: Computer Science
Instructions:
SLLQueue (13 pts)
● Using the three properties below, implement the
queue interface using the SLLNode class from Lab 2:
○ head_node → SLLNode object or None
○ tail_node → SLLNode object or None
○ size → int, keep track of queue size
● Implement enqueue( ), dequeue( ), front( )
● Use SLLNode methods:
get_item( ), set_item( ), get_next( ), set_next( )
● (5 pts) In enqueue(item):
○ Add new SLLNode (with item) after tail_node
○ Update tail_node and size properties
○ If first item, update head_node property too
● (6 pts) In dequeue( ):
○ If empty, raise Exception('Empty queue: cannot dequeue')
○ Remove head node and return its item
○ Remove any links from old head node
○ Update head_node and size properties
○ If queue becomes empty, reset head_node, tail_node
● (2 pts) In front( ):
○ If empty, raise Exception(Empty queue: no front')
○ Return head node’s item
Code:
class SLLQueue:
def __init__(self):
# NOTE: DO NOT EDIT THIS CODE
# constructor: set properties
head_node, tail_node, size
self.head_node = None
self.tail_node = None
self.size = 0
def __repr__(self):
# NOTE: DO NOT EDIT THIS CODE
# string representation of SLLQueue
object
display = []
node = self.head_node
while node != None:
display.append(str(node.get_item()))
node =
node.get_next()
display = ', '.join(display)
return 'front [' + display +
']'
def is_empty(self):
# NOTE: DO NOT EDIT THIS CODE
# check if queue is empty
return self.size == 0
def enqueue(self,item):
# TODO: Write your code
here...
# TODO: add new node (with item)
after tail_node
# TODO: update tail_node and size
properties
# TODO: if this is the first node
added, update head_node too
pass # TODO: remove this line
def dequeue(self):
# TODO: Write your code
here...
# TODO: if empty, raise
Exception('Empty queue: cannot dequeue')
# TODO: remove head_node and return
its item
# TODO: remove any links from old
head_node (Hint: set to None)
# TODO: update head_node and size
properties
# TODO: if queue becomes empty,
reset head_node and tail_node
pass # TODO: remove this line
def front(self):
# TODO: Write your code
here...
# TODO: if empty, raise
Exception('Empty queue: no front')
# TODO: return head_node's item
pass # TODO: remove this line
In: Computer Science
QUESTION 6
A single line comment in C++ language source code can begin with _____
a) //
b) ;
c) :
d) /*
QUESTION 7
What is the output of the following program?
#include<iostream> using namespace std; class abc { public: int i; abc(int i) { i = i; } }; main() { abc m(5); cout<<m.i; }
a)Garbage
b)5
c)Compile Error
d)None of the answers
QUESTION 8
The following operator can be used to calculate the value of one number raised to another.
a)None of the answers
b) ^
c)**
d) ^^
QUESTION 9
What is the output of the following program?
#include <iostream> using namespace std; int main () { // local variable declaration: int x = 1; switch(x) { case 1 : cout << "Hi!" << endl; break; default : cout << "Hello!" << endl; } }
a) Hi
b)Hello
c)HelloHi
d)Compile Error
QUESTION 10
What is the output of the following program?
#include<iostream> using namespace std; main() { int a[] =
{1, 2}, *p = a; cout<<p[1]; }
a)2
b)1
c)Compile Error
d)Runtime Error
In: Computer Science
Cyber Security is a major concern to legitimate businesses around the world. It is also the largest growing illegitimate business. What are the 2 to main attack vectors on the technical side discussed in class? What is the 1 main vector for attack on the social engineering side? Explain how IT managers can best thwart attacks. What is a good business approach to creating a solid defense strategy? Explain the elements.
Please explain thoroughly wit at least 500 words. do not copy paste answers from the web too i can. do that as well. Thank you very much.
In: Computer Science
Module 2 Programming Assignment – Battleship Refactor
Refactor your Battleship drawing code from Module 1.
Download the OO template for the basic battleship game, BattleshipRefactor.zip (refer below)
The template has the outline of a battleship game using OO constructs. You need to add the Grid class and complete the code so that it runs correctly.
At a minimum, you need to complete the Draw and DropBomb methods with code similar to the previous assignment. There will be changes due to the different layout, but the core of your code will do the same thing.
In this Module we are adding 2 new features:
You may add as many other methods, fields or properties as you feel are required for the assignment.
Notes:
The code will be tested with grids ranging in size from 5 (the smallest you can fit a size 5 ship) upwards. Make sure that all aspects of the game work correctly without crashing or hanging.
You must use the template code provided!
Like in Module 1, please make sure you show the ships in the grid. At this point we are merely testing our game logic and hidden ships make the game very hard to test.
BattleShipGame.cs
using System;
namespace BattleshipSimple
{
internal class BattleShipGame
{
private Grid grid;
public BattleShipGame(int gridSize)
{
grid = new Grid(gridSize);
}
internal void Reset()
{
grid.Reset();
}
internal void Play()
{
while (grid.HasShipsLeft)
{
grid.Draw();
//Read input from user into x, y
int x, y;
grid.DropBomb(x, y);
}
}
}
}
Program.cs
using System;
namespace BattleshipSimple
{
class Program
{
static void Main(string[] args)
{
var game = new BattleShipGame(10);
ConsoleKeyInfo response;
do
{
game.Reset();
game.Play();
Console.WriteLine("Do you want to play again (y/n)");
response = Console.ReadKey();
} while (response.Key == ConsoleKey.Y);
}
}
}
In: Computer Science