Questions
I've already worked on isEmpty, so please check that and solve the other parts to the...

I've already worked on isEmpty, so please check that and solve the other parts to the question as well. Will rate as soon an I see that it is answered.

In this section, you will implement a generic Stack class implemented using linked list. Assume the linked list node class is already defined as below:
public class LLNode<T> {
public LLNode<T> link;

public T info;

public LLNode(T in) { info = in; link = null; }

}

Note that both class variables are public so any outside class can access them directly. Also assume that class StackUnderflowException has been defined that inherits Java’s Exception class. Your task is to implement four methods in the generic class LinkedListStack<T>.

public class LinkedListStack<T> {

private LLNode<T> head; // head of linked list, also stack top pointer

public LinkedListStack() { head = null; } // constructor

public boolean isEmpty() { // [1 pts]

// TODO: return true if stack is empty, false otherwise

// NO MORE THAN 1 LINE OF CODE!

if(head.link == null) return true;

}

public void push(T element) { // [2 pts]

// TODO: push an element to the stack

// NO MORE THAN 3 LINES of CODE!

}

public T peek() throws StackUnderflowException { // [2 pts]

// TODO: return the top element of the stack (but do NOT
// remove it). NO MORE THAN 4 LINES of CODE!

}

public T pop() throws StackUnderflowException { // [3 pts]

// TODO: remove and return the top element of the stack

// It throws StackUnderflowException if stack is empty

// NO MORE THAN 6 LINES of CODE!

}

In: Computer Science

C++. Write a program that uses for loops to perform the following steps: a. Prompt the...

C++. Write a program that uses for loops to perform the following steps:
a. Prompt the user to input two positive integers. variables: firstNum and secondNum (firstNum must be less than secondNum). Validate the user's input; prompt the user again if firstNum is not less than secondNum (use for loop).
b. Output all odd numbers between firstNum and secondNum. (use for loop).
c. Output the sum of all even numbers between firstNum and secondNum. (use for loop).
d. Output the numbers and their squares between 1 and 10. (use for loop).
e. Output the sum of the square of the odd numbers between firstNum and secondNum. (use for loop)
f. Output all uppercase letters. (use for loop).

In: Computer Science

Change the program to modify the output file by making each sentence a new paragraph (inserting...

Change the program to modify the output file by making each sentence a new paragraph (inserting two carriage returns between every sentence. :) Don't over-think this, but you must have worked through and understand how the program works now in order to modify it. Remember, you want the carriage returns between every SENTENCE, not every LINE.

How would one do this? I'm not to sure how to make it make a new line after a sentence. Any help will be appreciated.

This is the original code that makes it make a new line after every carriage return. I need it to make a new line after every sentence.

Here is the input text file :  

Today we live in an era where information is processed
almost at the speed of light. Through computers, the
technological revolution is drastically changing the way we
live and communicate with one another. Terms such as
“the Internet,” which was unfamiliar just a few years ago, are
very common today. With the help of computers you can send
letters to, and receive letters from, loved ones within
seconds. You no longer need to send a résumé by mail to apply
for a job; in many cases you can simply submit your job
application via the Internet. You can watch how stocks perform
in real time, and instantly buy and sell them. Students
regularly “surf” the Internet and use computers to design
their classroom projects. They also use powerful word
processing software to complete their term papers. Many
people maintain and balance their checkbooks on computers.

//*************************************************************
// Author: D.S. Malik
//
// Program: Line and Letter Count
// This program reads a text, outputs the text as is, and also
// prints the number of lines and the number of times each
// letter appears in the text. An uppercase letter and a
// lowercase letter are treated as being the same; that is,
// they are tallied together.
//*************************************************************

#include
#include
#include

using namespace std;

void initialize(int& lc, int list[]);
void characterCount(char ch, int list[]);
void copyText(ifstream& intext, ofstream& outtext, char& ch,
int list[]);
void writeTotal(ofstream& outtext, int lc, int list[]);

int main()
{
//Step 1; Declare variables
int lineCount;
int letterCount[26];
char ch;
ifstream infile;
ofstream outfile;

infile.open("textin.txt"); //Step 2

if (!infile) //Step 3
{
cout << "Cannot open the input file."
<< endl;
return 1;
}

outfile.open("textout.out"); //Step 4

initialize(lineCount, letterCount); //Step 5

infile.get(ch); //Step 6

while (infile) //Step 7
{
copyText(infile, outfile, ch, letterCount); //Step 7.1
lineCount++; //Step 7.2
infile.get(ch); //Step 7.3
}

writeTotal(outfile, lineCount, letterCount); //Step 8

infile.close(); //Step 9
outfile.close(); //Step 9
  
return 0;
}

void initialize(int& lc, int list[])
{
int j;
lc = 0;

for (j = 0; j < 26; j++)
list[j] = 0;
} //end initialize

void characterCount(char ch, int list[])
{
int index;

ch = toupper(ch); //Step a

index = static_cast(ch)
- static_cast('A'); //Step b

if (0 <= index && index < 26) //Step c
list[index]++;
} //end characterCount

void copyText(ifstream& intext, ofstream& outtext, char& ch,
int list[])
{
while (ch != '\n') //process the entire line
{
outtext << ch; //output the character
characterCount(ch, list); //call the function
//character count
intext.get(ch); //read the next character
}
outtext << ch; //output the newline character
} //end copyText

void writeTotal(ofstream& outtext, int lc, int list[])
{
int index;

outtext << endl << endl;
outtext << "The number of lines = " << lc << endl;

for (index = 0; index < 26; index++)
outtext << static_cast(index + static_cast('A'))
<< " count = " << list[index] << endl;
} //end writeTotal

This is the code I've got so far to make it ask for what the output file should be named.

//*************************************************************
// Author: D.S. Malik
//
// Program: Line and Letter Count
// This program reads a text, outputs the text as is, and also
// prints the number of lines and the number of times each
// letter appears in the text. An uppercase letter and a
// lowercase letter are treated as being the same; that is,
// they are tallied together.
//*************************************************************

#include
#include
#include

using namespace std;

void initialize(int& lc, int list[]);
void characterCount(char ch, int list[]);
void copyText(ifstream& intext, ofstream& outtext, char& ch,
int list[]);
void writeTotal(ofstream& outtext, int lc, int list[]);

int main()
{
//Step 1; Declare variables
int lineCount;
int letterCount[26];
char ch;
ifstream infile;
ofstream outfile;
string fileName;
  
infile.open("textin.txt"); //Step 2

if (!infile) //Step 3
{
cout << "Cannot open the input file."
<< endl;
return 1;
}

cout << "Please enter the name of the output file: "; <----- This is the new code
getline(cin, fileName); <----- This is the new code

outfile.open(fileName.c_str()); //Step 4 <----- This is the new code

initialize(lineCount, letterCount); //Step 5

infile.get(ch); //Step 6

while (infile) //Step 7
{
copyText(infile, outfile, ch, letterCount); //Step 7.1
lineCount++; //Step 7.2
infile.get(ch); //Step 7.3
}

writeTotal(outfile, lineCount, letterCount); //Step 8

infile.close(); //Step 9
outfile.close(); //Step 9
  
return 0;
}

void initialize(int& lc, int list[])
{
int j;
lc = 0;

for (j = 0; j < 26; j++)
list[j] = 0;
} //end initialize

void characterCount(char ch, int list[])
{
int index;

ch = toupper(ch); //Step a

index = static_cast(ch)
- static_cast('A'); //Step b

if (0 <= index && index < 26) //Step c
list[index]++;
} //end characterCount

void copyText(ifstream& intext, ofstream& outtext, char& ch,
int list[])
{
while (ch != '\n') //process the entire line
{
outtext << ch; //output the character
characterCount(ch, list); //call the function
//character count
intext.get(ch); //read the next character
}
outtext << ch; //output the newline character
} //end copyText

void writeTotal(ofstream& outtext, int lc, int list[])
{
int index;

outtext << endl << endl;
outtext << "The number of lines = " << lc << endl;

for (index = 0; index < 26; index++)
outtext << static_cast(index + static_cast('A'))
<< " count = " << list[index] << endl;
} //end writeTotal

In: Computer Science

Discuss the roles of information policy and data administration in information management.

Discuss the roles of information policy and data administration in information management.

In: Computer Science

Summary In this lab, you complete a prewritten Java program that calculates an employee’s productivity bonus...

Summary

In this lab, you complete a prewritten Java program that calculates an employee’s productivity bonus and prints the employee’s name and bonus. Bonuses are calculated based on an employee’s productivity score as shown below. A productivity score is calculated by first dividing an employee’s transactions dollar value by the number of transactions and then dividing the result by the number of shifts worked.

Productivity Score Bonus
<=30 $50
31–69 $75
70–199 $100
>= 200 $200

Instructions

  1. Ensure the file named EmployeeBonus.java is open.

  2. Variables have been declared for you, and the input statements and output statements have been written. Read them over carefully before you proceed to the next step.

  3. Design the logic, and write the rest of the program using a nested if statement.

  4. Execute the program by clicking Run and enter the following as input:

    Employee’s first name: Kim Smith  
    Number of shifts: 25  
    Number of transactions: 75  
    Transaction dollar value: 40000.00
  5. Your output should be:
    Employee Name: Kim Smith  
    Employee Bonus: $50.0
              
    
  6. // EmployeeBonus.java - This program calculates an employee's productivity bonus.

    import java.util.Scanner;

    public class EmployeeBonus
    {
       public static void main(String args[])
       {
           Scanner s = new Scanner(System.in);
           // Declare and initialize variables here.
           String employeeName;
           double numTransactions;
           String transactString;
           double numShifts;
           String shiftString;
           double dollarValue;
           String dollarString;
           double score;
           double bonus;
      
           final double BONUS_1 = 50.00;
           final double BONUS_2 = 75.00;
           final double BONUS_3 = 100.00;
           final double BONUS_4 = 200.00;
          
                  
           // This is the work done in the housekeeping() method
    System.out.println("Enter employee's name: ");
    employeeName = s.nextLine();
           System.out.println("Enter number of shifts: ");
           shiftString = s.nextLine();
           System.out.println("Enter number of transactions: ");
           transactString = s.nextLine();
           System.out.println("Enter transactions dollar value: ");
           dollarString = s.nextLine();

           numShifts = Double.parseDouble(shiftString);
           numTransactions = Double.parseDouble(transactString);
           dollarValue = Double.parseDouble(dollarString);
           // This is the work done in the detailLoop() method
           // Write your code here
          
           // This is the work done in the endOfJob() method  
           // Output.
           System.out.println("Employee Name: " + employeeName);
           System.out.println("Employee Bonus: $" + bonus);

           System.exit(0);
       }
    }   

In: Computer Science

. A heart rate monitor measures an individuals heart rate and blood pressure. Both sensors output...

. A heart rate monitor measures an individuals heart rate and blood

pressure. Both sensors output zero (0) if they are within safety range. An alarm will sound if either sensor indicates an unsafe condition is present.Set–up the appropriate truth table, simplify using K–maps. Implement, using LogiSim, the simplified logic circuit with optimal number of logic gates.

In: Computer Science

In the program P81.cpp and P81a.cpp, you learned to define friend functions to access the variable...


In the program P81.cpp and P81a.cpp, you learned to define friend functions to access the variable members of a class. In those programs, you used a function called add to do the addition of money (dollars and cents), and similarly did the subtraction of money using the subtract function.   Since the addition or subtraction of money required two components, it was different from an arithmetic add operation. In C++, we can overload the add operator, ''+", to do different types of addition, for example: an the addition of money in the previous programs (dollars + dollars and cents + cents). By using function overloading, we will give the power of function add to operator "+", which is also defined in the class definition.

Before we give an example of overloading operators, let's look at a new version of P81a.cpp in which the add function is defined as a friend and has the new type of AltMoney.

// P82.cpp - This program adds money of two different people
#include<iostream>
#include<cstdlib>
using namespace std;

class AltMoney
{
    public:
        AltMoney();
        AltMoney(int d, int c);

        friend AltMoney add(AltMoney m1, AltMoney m2);
        void display_money( );
    private:
        int dollars;
        int cents;
};

void read_money(int& d, int& c);

int main( )
{
     int d, c;
     AltMoney m1, m2, sum;

     sum = AltMoney(0,0);

     read_money(d, c);
     m1 = AltMoney(d,c);
     cout << "The first money is:";
     m1.display_money();

     read_money(d, c);
     m2 = AltMoney(d,c);
     cout << "The second money is:";
     m2.display_money();

     sum = add(m1,m2);
     cout << "The sum is:";
     sum.display_money();

     return 0;
}

AltMoney::AltMoney()
{
}

AltMoney::AltMoney(int d, int c)
{
       dollars = d;
       cents = c;
}

void AltMoney::display_money()
{
     cout << "$" << dollars << ".";
     if(cents <= 9)
         cout << "0"; //to display a 0 on the left for numbers less than 10
     cout << cents << endl;
}

AltMoney add(AltMoney m1, AltMoney m2)
{
     AltMoney temp;
     int extra = 0;
     temp.cents = m1.cents + m2.cents;
     if(temp.cents >=100){
         temp.cents = temp.cents - 100;
         extra = 1;
      }
      temp.dollars = m1.dollars + m2.dollars + extra;

      return temp;
}

void read_money(int& d, int& c)
{
     cout << "Enter dollar \n";
     cin >> d;
     cout << "Enter cents \n";
     cin >> c;
     if( d < 0 || c < 0)
     {
            cout << "Invalid dollars and cents, negative values\n";
            exit(1);
      }
}

In this program the add is defined as a friend and has the type AltMoney as well.

Now, let's overload the "+" operator so that is does what the function add is doing.

Here are the changes that you need to make: (red font)

1) In class AltMoney:
class AltMoney
{
    public:
        AltMoney();
        AltMoney(int d, int c);

        friend AltMoney operator +(AltMoney m1, AltMoney m2);
        void display_money( );
    private:
        int dollars;
        int cents;
};

2) In the main:

     sum = m1+m2;

3) In the function definition
AltMoney operator +(AltMoney m1, AltMoney m2)
{
     AltMoney temp;
     int extra = 0;
     temp.cents = m1.cents + m2.cents;
     if(temp.cents >=100){
         temp.cents = temp.cents - 100;
         extra = 1;
      }
      temp.dollars = m1.dollars + m2.dollars + extra;

      return temp;
}

By making these changes, you can now add two objects of type AltMoney. Note that you may overload "+" in another class definition. Depending on how you have defined it, "+" operation may have different meanings in such cases.

Exercise 8.2
First make the above changes in P82.cpp and call the new program ex82.cpp. Compile and run the program and make sure it produces the correct results. Here is what you need to do for the exercise:

    Overload the % operator such that every time you use it, it takes two objects of type AltMoney as its arguments and returns:
            a) 5% of the difference between the income and expenditure, if income is larger than the expenditure
            b) -2% if the the expenditure is larger than the income.
            c) 0 if the expenditure is the same as income
Note that, by doing this, you are required to overload the greater than sign (>), the smaller than sign (<), and the == sign.

In: Computer Science

Credit Cards Credit card numbers follow patterns. Cards must have 13 - 16 digits (inclusive) Card...

Credit Cards

Credit card numbers follow patterns.

  1. Cards must have 13 - 16 digits (inclusive)
  2. Card numbers must start with the number(s):
    • 4 for Visa cards
    • 5 for MasterCard cards
    • 37 for American Express cards
    • 6 for Discover cards

Given that a number has satisfied the above criteria A and B the following steps are taken to validate the number:

  1. Double every second digit from right to left.  If doubling the digit results in a two-digit number, add the two digits to get a single digit number
  2. Add all of the single digit numbers from step 1 above
  3. Add all of the digits in the odd places from right to left in the card number
  4. Sum the results from steps 2 and 3 above
  5. If the result from step 4 is evenly divisible by 10 the card number is valid.

Given the number:

4388576018402626

The steps 1 - 5 above would be (after determining that A an B above have been satisfied):

Step 1:

2 * 2 = 4

2 * 2 = 4

4 * 2 = 8

1 * 2 = 2

6 * 2 = 12 ( 1 + 2 = 3)

5 * 2 = 10 (1 + 0 = 1)

8 * 2 = 16 (1 + 6 = 7)

4 * 2 = 8

Step 2:

4 + 4 + 8 + 2 + 3 + 1 + 7 + 8 = 37

Step 3:

6 + 6 + 0 + 8 + 0 + 7 + 8 + 3 = 38

Step 4:

37 + 38 = 75

Step 5:

75 % 10

You are to write a program that will prompt the user to enter a card number.  You are then to determine if the number entered is valid or not.  You are then to print to the screen if the number entered is a valid credit card number or not.

Your are to complete this program using functions. You are to have a function main in which you will only call the functions you have developed.  The last line of your code is to be a call to main as below:

main()

Here are some valid numbers for testing purposes:

American Express

378282246310005

American Express

371449635398431

Discover

6011111111111117

Discover

6011000990139424

MasterCard

5555555555554444

MasterCard

5105105105105100

Visa

4111111111111111

Visa

4012888888881881

Visa

4222222222222

Done in Python Format please

In: Computer Science

Write a program that prompts the user for a file name, make sure the file exists...

Write a program that prompts the user for a file name, make sure the file exists and then reads through the file, counts the number of times each word appears and outputs the word count in a sorted order from high to low.

The program should:

  • Display a message stating its goal
  • Prompt the user to enter a file name
  • Check that the file can be opened and if not ask the user to try again (hint: use the try/except structure)
  • Count the number of times each word appears in the file, regardless if in lowercase or uppercase (hint: use dictionaries and the lower() function)
  • Display the word count in order from high to low
  • Bonus: if a few words have the same count, sort the display in an alphabetic order
  • For example, for the attached file NYT2.txt, the top five words in the output should be

the - 7

in - 6

to - 5

and - 4

of - 4

File Name: NYT2.txt

File Content:

Fact-Checking Trump’s Orlando Rally: Russia, the Wall and Tax Cuts
President Trump delivered remarks in Florida in a formal start to his re-election effort.
Deutsche Bank Faces Criminal Investigation for Potential Money-Laundering Lapses        
Federal authorities are focused on whether the bank complied with anti-money-laundering laws, including in its review of transactions linked to Jared Kushner.
Five NY1 Anchorwomen Sue Cable Channel for Age and Gender Discrimination
The women, including Roma Torre, say their careers were derailed after Charter Communications bought New York’s hometown news station in 2016.
Hypersonic Missiles Are Unstoppable. And They’re Starting a New Global Arms Race.
The new weapons — which could travel at more than 15 times the speed of sound with terrifying accuracy — threaten to change the nature of warfare.
Nxivm’s Keith Raniere Convicted in Trial Exposing Sex Cult’s Inner Workings
Mr. Raniere set up a harem of sexual “slaves” who were branded with his initials and kept in line by blackmail.
Jamal Khashoggi Was My Fiancé. His Killers Are Roaming Free.
Washington hasn’t done enough to bring the murdered Saudi columnist’s killers to justice.

In: Computer Science

If the value of semaphore is negative, ___? A. an increment operation can be perform on...

If the value of semaphore is negative, ___?

A. an increment operation can be perform on it.

B. a process is waiting forever.

C. there will be no process waiting on that semaphore.
D. a decrement can be perform on it.

((( ( can negative semaphore decreases in case of more waiting processes? Explain in details. )))

In: Computer Science

In a file called LengthSum.java, write a program that: Asks the user to enter a string....

In a file called LengthSum.java, write a program that:

  • Asks the user to enter a string.
  • Asks the user to enter a second string.
  • Prints out the length of the first string, the length of the second string, and the sum of the two lengths, using EXACTLY the same format as shown below.

For example: if the user enters strings "UT" and "Arlington", your program output should look EXACTLY like this:

Please enter a string: UT
Please enter a second string: Arlington
The first string has length 2.
The second string has length 9.
The sum of the two lengths is 11.

Your program's output should match EXACTLY the format shown above. There should be no deviations, no extra spaces or lines, no extra punctuation in your output. What you see above as uppercase letters should remain uppercase in your output, what you see as lowercase letters should remain as lowercase in your output, what you see as spaces and punctuation should remain exactly as spaces and punctuation in your output.

In: Computer Science

Explain the two different categories of Application layer protocols, and then detail the PDU used at...

Explain the two different categories of Application layer protocols, and then detail the PDU used at this layer.​

In: Computer Science

How can you prevent damage to a component prior to touching it?​

How can you prevent damage to a component prior to touching it?​

In: Computer Science

Write a Java program (single file/class) whose filename must be Numbers.java. The program reads a list...

Write a Java program (single file/class) whose filename must be Numbers.java. The program reads a list of integers from use input and has the following methods: 1. min - Finds the smallest integer in the list. 2. max- Finds the largest integer in the list. 3. average - Computes the average of all the numbers. 4. main - method prompts the user for the inputs and ends when the user enter Q or q and then neatly outputs the entire list of entries on one line and then the minimum, maximum, and average. values on separate lines with nice readable labels. 5. Make sure your code runs without error and handles bad inputs and 0 and negative numbers are valid. 6. Followed instructions and include to get full credit file must include your name, date, class and Javadoc code comments for each and every method as well as logic comments.m

In: Computer Science

Java program Create class DateClass with the following capabilities: Output the date in multiple formats, such...

Java program

Create class DateClass with the following capabilities:

Output the date in multiple formats, such as

MM/DD/YYYY
June 14, 1992
DDD YYYY

Use overloaded constructors to create DateClass objects initialized with dates of the formats in part (a). In the first case the constructor should receive three integer values. In the second case it should receive a String and two integer values. In the third case it should receive two integer values, the first of which represents the day number in the year.

If someone enters the day as the 14 and the month is june, the program should be able to convert that to the day out of 365 for the third format. No null values. The program should convert whatever the user enters and print out all three date formats correctly.

In: Computer Science