Questions
C++ question. I want to write all output to the file "output.txt", but it will write...

C++ question.

I want to write all output to the file "output.txt", but it will write just first character. Can you fix it?

#include

#include

#include

#include

#include

using namespace std;

using std::cin;

using std::cout;

using std::string;

// remove dashes convert letters to upper case

string normalize(const string &isbn) {

string ch;

for (char i : isbn) {

if (i == '-') {

continue; // if "-" then skip it

}

  

if (isalpha(i)) {

i = toupper(i); // Check uppercase

}

ch += i;

}

return ch;

}

// return the number of digits in to the string

size_t numDigits(string &str) {

size_t numDigits = 0;

for (char ch : str) {

if (isdigit(ch)) {

++numDigits;

}

}

return numDigits;

}

enum ValidationCode {

Ok, // validation passed

NumDigits, // wrong number of digits

ExtraChars,// extra characters in isbn

Done

};

enum ValidationCode validate(string &isbn) {

int Done = 4;

string normal = normalize(isbn);

size_t count = numDigits(normal);

if (normal.size() == Done)

exit(0);

if (count != 10) {

return NumDigits;

}

  

if (normal.size() == 10 || normal.size() == 11 && normal[10] == 'X') {

return Ok;

}

return ExtraChars;

}

int main() {

// open a file

ofstream file("output.txt");

//The following code is taken from (https://en.cppreference.com/w/cpp/io/basic_ios/fail)

// check if the file can open

if(!file) // operator! is used here

{

std::cout << "File opening failed\n";

return EXIT_FAILURE;

} //end of borrowed code

  

// read a file

//The following code is referenced from (https://stackoverflow.com/questions/7868936/read-file-line-by-line-using-ifstream-in-c)

std::ifstream ifs("test_data.txt");

// check if the file can read

if (ifs.fail())

{

std::cerr << "test_data.txt could not read" << std::endl;

return -1;

} //end of referenced code

std::string str;

while (ifs >> str){

switch (validate(str)) {

case Ok:

cout << str << " is a valid isbn\n";

file << str << " is a valid isbn\n";

break;

case NumDigits:

cout << str << " doesn't have 10 digits\n";

file << str << " doesn't have 10 digits\n";

break;

case ExtraChars:

cout << str << " has extra characters\n";

file << str << " has extra characters\n";

break;

default:

cout << "ERROR: validate(" << str << ") return an unknown status\n";

file << "ERROR: validate(" << str << ") return an unknown status\n";

break;

}

}

ifs.close();

file.close();

}

test_data.txt

1-214-02031-3
0-070-21604-5
2-14-241242-4
2-120-12311-x
0-534-95207-x
2-034-00312-2
1-013-10201-2
2-142-1223
3-001-0000a-4
done

In: Computer Science

STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop...

STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int -*mySet: myType -MAX_VALUE = 500000 static const: int -LIMIT = 1000 static const: int +recursionSet() +recursionSet(const recursionSet&) +~recursionSet() +getSetLength() const: int +generateElements(int): void + getElement(int) const: myType +setElement(int, myType): void +readValue(const string) const: int +printSet() const: void +operator == (const recusrionSet&): bool +tak(myType, myType, myType) const: myType +printSeptenary(myType) const: void +squareRoot(myType, myType) const: myType -recSqRoot(myType, myType, myType) const: myType +recursiveSum() const: myType -rSum(int) const: myType +checkParentheses(string) const: bool -recChkPar(string, int, int) const: bool +recursiveInsertionSort(): void -recInsSort(int, int): void -insertInOrder(myType, int, int): voidYou may add additional private functions if needed (but, not for the recursive functions). Note, points will be deducted for especially poor style or inefficient coding. Function Descriptions • The recursionSet() constructor should set the length to 0 and mySet pointer to NULL. • The recusrsionSet(const recursionBucket&) copy constructor should create a new, deep copy from the passed object. • The ~recursionSet() destructor should delete the myType array, set the pointer to NULL, and set the size to 0. • The setElement(int, myValue) function should set an element in the class array at the given index location (over-writing any previous value). The function must include bounds checking. If an illegal index is provided, a error message should be displayed. • The getElement(int) should get and return an element from the passed index. This must include bounds checking. If an illegal index is provided, a error message should be displayed and a 0 returned. • The getSetLength() functions should return the current class array length. • The printSet(int) function should print the formatted class array with the passed number of values per line. Use the following output statement: cout << setw(5) << mySet[i] << " • "; Refer to the sample executions for formatting example. The readValue(string) function should prompt with the passed string and read a number from the user. The function should ensure that the value is 3 1 and £ MAX_VALUE. The function should handle invalid input (via a try/catch block). If an error occurs (out of range or invalid input) an appropriate message should be displayed and the user re- prompted. Example error messages include: cout << "readSetLenth: Sorry, too many " << "errors." << endl; cout << "readSetLenth: Error, value " << cnt << " not between 1 and " << numMax << "." << endl; • Note, three errors is acceptable, but a fourth error should end the function and return 0. The generateList(int) function should dynamically create the array and use the following casting for rand() to fill the array with random values. mySet[i] = static_cast(rand()%LIMIT); • • • The printSeptenary(myType) function should print the passed numeric argument in Septenary (base-7) format. Note, function must be written recursively. The recursiveSum() function will perform a recursive summation of the values in class data set and return the final sum. The function will call the private rSum(int) function (which is recursive). The rSum(int) function accepts the length of the data set and performs a recursive summation. The recursive summation is performed as follows: rSum ( position )= • { array[ 0] array[ position ] + rSum ( position−1) if position = 0 if position > 0 The tak(myType) function should recursively compute the Tak 1 function. The Tak function is defined as follows: tak ( x , y , z) = { z tak ( tak ( x−1, y , z) , tak ( y−1, z , x) , tak ( z −1, x , y ) ) 1 For more information, refer to: http://en.wikipedia.org/wiki/Tak_(function) if y≥ x if y < x• • The squareRoot(myType, myType) function will perform a recursive estimation of the square root of the passed value (first parameter) to the passed tolerance (second parameter). The function will call the private sqRoot(myType,myType,myType) function (which is recursive). The private recSqRoot(myType,myType,myType) function recursively determines an estimated square root. Assuming initially that a = x, the square root estimate can be determined as follows: recSqRoot ( x , a , epsilon) = • • • • • { 2 if ∣ a − x ∣ ≤ epsilon a 2 (a + x) sqRoot x , , epsilon 2 a ( ) if ∣ a 2 − x ∣ > epsilon The recursiveInsertionSort() function should sort the data set array using a recursive insertion sort. The recursiveInsertionSort() function should verify the length is valid and, if so, call the recInsSort() function to perform the recursive sorting (with the first element at 0 and the last element at length-1). The recInsSort(int, int) function should implement the recursive insertion sort. The arguments are the index of the first element and the index of the last element. If the first index is less than that last index, the recursive insertion sort algorithm is follows: ▪ Recursively sort all but the last element (i.e., last-1) ▪ Insert the last element in sorted order from first through last positions To support the insertion of the last element, the insertInOrder() function should be used. The insertInOrder(myType, int, int) function should recursively insert the passed element into the correction position. The arguments are the element, the starting index and the ending index (in that order). The function has 3 operations: ▪ If the element is greater than or equal to the last element in the sorted list (i.e., from first to last). If so, insert the element at the end of the sorted (i.e, mySet[last+1] = element). ▪ If the first is less than the last, insert the last element (i.e., mySet[last]) at the end of the sorted (i.e., mySet[last+1] = mySet[last]) and continue the insertion by recursively calling the insertInOrder() function with the element, first, and last-1 values. ▪ Otherwise, insert the last element (i.e., mySet[last]) at the end of the sorted (i.e., mySet[last+1] = mySet[last]) and set the last value (i.e., mySet[last]) to the passed element. The checkParentheses(string) function should determine if the parentheses in a passed string are correctly balanced. The function should call the private recChkPar(string, int, int) function (which is recursive) The recChkPar(string, int, int) function should determine if the parentheses in a string are correctly balanced. The arguments are the string, an index (initially 0), and a parenthesis level count (initially 0). The index is used to track the current character in the string. The general approach should be as follows: ◦ Identify base case or cases. ◦ Check the current character (i.e., index) for the following use cases: ▪ if str[index] == '(' → what to do then ▪ if str[index] == ')' → what to do then ▪ if str[index] == any other character → what to do then Note, for each case, increment the index and call function recursively.

In: Computer Science

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