Questions
Write an algorithm (flowchart OR Pseudocode) for the following problem Take input character from the user...

Write an algorithm (flowchart OR Pseudocode) for the following problem
Take input character from the user unless he enters '$'. Thereafter display how may vowels were entered by the user. Also display the number of each vowel ('a', 'e', 'i', 'o' and 'u') separately.
For example if the user enters B
a
b
e
c
o
o
d
i
u
g
o
a
l
$
Then we have the output below:
#A=2
#E=1
#I=1
#O=3
#U=2

In: Computer Science

This class should include .cpp file, .h file and driver.cpp (using the language c++)! Overview of...

This class should include .cpp file, .h file and driver.cpp (using the language c++)!

Overview of complex Class

The complex class presents the complex number X+Yi, where X and Y are real numbers and i^2 is -1. Typically, X is called a real part and Y is an imaginary part of the complex number. For instance, complex(4.0, 3.0) means 4.0+3.0i. The complex class you will design should have the following features.

Constructor

Only one constructor with default value for Real = 0.0, Imaginary = 0.0; But it should construct the complex numbers with, 1) no argument, 2) 1 argument, 3) 2 arguments. Please refer the rat2.h file and rat2.cpp.

Data members

The complex has two members which should be Real values. For example, x+yi, Real = x, Imaginary = y.

Member functions : Provide the following four member functions:

getReal

returns the real part of the complex.

getImaginary

returns the imaginary part of this complex number.

setReal

sets the real part of the complex.

setImaginary

sets the imaginary part of this complex number.

Math operators

The class must implement binary arithmetic operations such as addition, subtraction, multiplication, and division. You should be able to use operators (+, -, *, /).

Addtion (+)

Add two objects. For example, (a+bi) + (c+di) = (a+c) + (b+d)i

Subtraction(-)

Perform complex minus operation

Multiplication(*)

Multiply the left-hand-side object by the right-hand-side and return complex object.

Division(/)

Divide the left-hand-side object by the right-hand-side object. You have to know the division of complex numbers. Divide by zero error should be handled in this method. That is, print an error message, and return the original one. Since it is an exception error, should not affect the following tasks. (Same for /= method)

Conjugate

The complex conjugate of the complex number z = x + yi is defined to be x − yi. This function returns the conjugate of the input complex.

Comparison

The class must implement ==. !=.

Assignment

The class must implement +=, -=, *= and /=. (Divide by zero error should be handled in /= method.)

Stream I/O

The class must implement the << and >> operators:

Input

Take two values as a real and imaginary value.

Output

The format will be: X+Yi, where X and Y are a Real and Imaginary value respectively. Of course, if either X or Y is 0, it should not be displayed. However, if both X and Y are 0, the output should be 0. Also note that if X is 1, it should be printed out as 1, and that if Y is 1, its output should be i. Wrong examples: 1+0 i, 0+2i, 1i, etc..In the case of Y be negative, it should not have “+” between the two. For example, print 2-3i, instead of 2+-3i.

In: Computer Science

Please code in C language. Server program: The server program provides a search to check for...

Please code in C language.

Server program:

The server program provides a search to check for a specific value in an integer array. The client writes a struct containing 3 elements: an integer value to search for, the size of an integer array which is 10 or less, and an integer array to the server through a FIFO. The server reads the struct from the FIFO and checks the array for the search value. If the search value appears in the array, the server indicates the index of the first occurrence of that value in the array. The server writes back to the client a struct that contains the search value and its array position. If the value does not occur in the array, the search value and an appropriate return code are returned to the client. (An appropriate return code for not finding the search value could be -1)

The server program needs to:

  • Create a well-known FIFO, named FIFO_to_Server through which the server reads a struct from the client
  • Open FIFO_to_Server in READ mode
  • Read a request from a client that includes a struct containing a search value, the size of the integer array and the array itself, all integers.
  • Find the index (start counting with zero) of the search value, if one exists
  • Create a FIFO named FIFO_to_Client through which the server responds to the client
  • Open FIFO_to_Client in WRITE mode
  • Write the search value and the index position back to the client through FIFO_to_Client
  • Close FIFO_to_Client
  • Unlink FIFO_to_Client
  • Close FIFO_to_Server
  • Unlink FIFO_to_Server

Client Program:

The client program requests an integer value to search for,  an array size and array elements to fill the array. The client program should:

  • Open FIFO_to_Server in WRITE mode
  • Prompt the user for a search value
  • Prompt the user for an array size
  • Prompt the user for elements to fill that array
  • Write the struct that includes the search value, the array size and the array to FIFO_to_Server
  • Close FIFO_to_Server *
  • Open the FIFO_to_Client in READ mode
  • Read the response from the server from FIFO_to_Client
  • Print a message such as “The value 87 occurs in array position 4”
  • Close FIFO_to Client

In: Computer Science

From the creation of the first Encyclopedia (1751) through Mauchly and Eckert’s ENIAC, through Bush’s memex,...

From the creation of the first Encyclopedia (1751) through Mauchly and Eckert’s ENIAC, through Bush’s memex, Alan Kay’s universal media machine, CALO, (Cognitive Agent that Learns and Organizes) to Google’s observation that algorithms need to answer, converse, and anticipate. Identify commonalities, and differences that run through the enterprise.

In: Computer Science

Working on a c++ data structures assignment.   Linked List add node. I have the head case...

Working on a c++ data structures assignment.  

Linked List add node. I have the head case and the tail case working but the middle/general case I can not get to work for the life of me. I have included the header file and the data struct file below  

#ifndef LINKEDLIST_H

#define LINKEDLIST_H

#include "data.h"

#include <iostream>   //take this out

using std::cout;


class LinkedList{

    public:

        LinkedList();

        ~LinkedList();

        bool addNode(int, string);

        bool deleteNode(int);

        bool getNode(int, Data*);

        void printList(bool = false);

        int getCount();

        void clearList();

        bool exists(int);

    private:

        Node *head;


};



#endif

----------------------------------------------------------------------------

#ifndef DATA_H

#define DATA_H

#include "string"

using std::string;

struct Data {

    int id;

    string data;

};

struct Node {

    Data data;

    Node *next;

    Node *prev;

};

#endif /* DATA_H */

---------------------------------------------------------------------------------------------------

bool LinkedList::addNode(int id, string data){

   bool success = false;

    Node *newNode = new Node;

    newNode -> data.id = id;

    newNode -> data.data = data;

    newNode -> next = NULL;

    newNode -> prev = NULL;

    Node *current;

    current = head;

    

     if(current == NULL && id > 0){                     

        head = newNode;                    

        success = true;

     }else if(newNode -> data.id <= current -> data.id && data != "" && id > 0 && id != current -> data.id){

        newNode -> next = current;

        newNode -> prev = NULL;

        head = newNode;

        success = true;

     }else {

         success = false;                 

     }

    

    while(current != NULL){

        if((current -> data.id < id) && data != "" && (current -> next == NULL)){            //tail case  

             current -> next = newNode;

             newNode -> prev = current;

             success = true;

         }else{

             current = current -> next;

         }  

    }

    while(current != NULL){

        if((current -> data.id < id) && (current -> prev -> data.id > id) && data != "" && (current -> next != NULL)){  //general or middle case

            cout << "test2" << std::endl;

            newNode -> next = current;  

            newNode -> prev -> next = newNode;

            current -> prev = newNode;

            success = true;

         }else{

             current = current -> next;

         }

    }

   return success;

}

In: Computer Science

Recall that an array could be a convenient way of storing the elements of a Heap....

Recall that an array could be a convenient way of storing the elements of a Heap. Give a Pseudocode that determines whether an array H[1..N] is indeed a Heap, i.e., it’s elements satisfy the Heap property.

In: Computer Science

Linux Directories, File Properties, and the File System in C Your version of find command Try...

Linux Directories, File Properties, and the File System in C

Your version of find command

  1. Try running the find command in the shell and observe the output. Try it in different folders to make sure you understand what it prints out.

    $ find

  2. Write your version of the find command and add comments.

In: Computer Science

What are the differences between CSMA/CA vs CSMA/CD?

What are the differences between CSMA/CA vs CSMA/CD?

In: Computer Science

a. Write a c++ function called IsPalindrome that receives a 3-digit number and returns whether it...

a. Write a c++ function called IsPalindrome that receives a 3-digit number and returns whether it is palindrome or not. [2.5 marks]

b. Write a c++ function, called GCD that receives two parameters n, d, and prints their greatest common divisor [2.5 marks]

  1. Now after you created the two functions, you have to write a main function that can call the above functions according to user choice. Write a menu that allows the user to select from the following options [5 marks]
  1. To use the IsPalindrome function you have to enter 1.
  2. To use the GCD function you have to enter 2.
  3. To Exit the program you have to enter 3. [use exit(0)]

Once the user select one of the above choices you have to read the value entered by the user and then to call the respective function.

In: Computer Science

For input you can either a console Scanner or a dialog box (a modal dialog) and...

For input you can either a console Scanner or a dialog box (a modal dialog) and the static method showInputDialog() of the JOptionPane class which is within the javax.swing package like this String name= newJOptionPane.showInputDialog(” Please enter your data:”). Then convert the String object to a number using Integer.parseInt() or Double.parseDouble()

----

Write a java the ”Letter grade” program that inputs several test scores from user and displays for each the corresponding letter grade using a scale 90 – 80 – 70 – 50. Test thoroughly the program with different data sets of your own.

In: Computer Science

Question3: Consider you have the following data for some user accounts: [6 marks] Username Password User1...

Question3: Consider you have the following data for some user accounts: [6 marks]


Username

Password

User1

101010

User2

112121

User3

211211

User4

312132


1. Write a function called validate which takes 2 arguments: a dictionary, a username, and a password. The function should do the following: [3 marks]

Find the given username in the dictionary and compare the given password with the one that belongs to that username in the dictionary. Return true if password is correct and false if password is wrong for that username.

2. Create a dictionary called users containing the data given in above table. [2 marks]

3. Call the validate function and pass the users dictionary along with any username and password of your choice to test the function. [1 marks]

In: Computer Science

Write a function called splice() that “splices” two integer arrays together by first allocating memory for...

Write a function called splice() that “splices” two integer arrays together by first allocating memory for a dynamic array with enough room for both integer arrays, and then copying the elements of both arrays to the new array as follows:

            first, copy the elements of the first array up to a given position,

            then, copy all the elements of the second array,

            then, copy the remaining elements in the first array.

The function should have parameters for the two input arrays, their lengths, and the number of elements of the first array to be copied before the second is spliced. The function should return a pointer to the new array.

To test the function, write a program that:

Prompts the user for the sizes of the two integer arrays and the number of

elements of the first array to be copied before the splice (e.g., 32 means insert

32 elements of the first array and then the second array),

Creates the two arrays and fills them with random values. Use the seed 100 for

srand().

Outputs the contents of the two input arrays in rows with 10 values/row.

Outputs the contents of the spliced array in rows with 10 values/row.

The program should use dynamic memory to store all three arrays. Be sure to de-allocate the memory before exiting. Your program must ensure that non-numeric and negative entries are not entered. Use modular design in your program. That is, separate functions should be used to fill the arrays with random numbers, print the arrays, and of course, splice the arrays together.

In: Computer Science

Question4: Create and use a lambda expression which calculates the sum of three numbers. Ask the...

Question4: Create and use a lambda expression which calculates the sum of three numbers. Ask the user for three numbers and use the lambda function to print the sum [6 marks]

Question5:

Write a generator function which generates the Fibonacci series. [0,1,2,4,8,16,…]. The Fibonacci series is a list of numbers where each number is the sum of the previous two. [3 marks]
Then write the code to iterate through the first six numbers of sequence. [3 marks]
Question6: Write a program to read the file 202010mid.txt, store the content in a list of tuples, then print the list. [6 marks]

Question7: Write Python code to do the following operations using request library. [12 marks]

Check if the following webpage is available or not: https://edition.cnn.com/news.html [4 marks]
Send a get request to the following webpage and show the result: http://api.open-notify.org/iss-pass.json [4 marks]
The webpage from part 2 is expecting some parameters as shown from the results. Now create a parameter with two key:value pairs as per the following: lat with value 40.71 and lon with value -74. Send a get request now with the parameter you created and display the result.[4 marks]

In: Computer Science

how can object -relational database be used to implement an SDBMS?

how can object -relational database be used to implement an SDBMS?

In: Computer Science

This program will focus on utilizing functions, parameters, Python's math and random modules, and if-statements! To...

This program will focus on utilizing functions, parameters, Python's math and random modules, and if-statements!

To Start: You should fork the provided REPL, run the program and observe the output, and then take a look through the code. You may not 100% understand the code, but taking a quick look through what's there will be helpful in the future.

You are going to systematically replace the TODO comments with code so that the program will work as intended.

  1. TODO 0 is in both main.py and coffee.py. Import the necessary functions from coffee.py into main.py. Then in coffee.py either import all of math and random right away, or import just the functions that you need as you write the code. DO NOT move the functions over to main.py. Use imports so that those functions can stay in coffee.py.
  2. TODO 1 is inside the get_num_drinks() function. You should set the variable num_drinks to a random number from 2 and 12 (inclusive) to simulate the number of drinks the customer is ordering. This is not user input. This is a computer-generated pseudorandom number using Python's random module (Links to an external site.).
  3. TODO 2 is below TODO 1. Print the random amount spent to the screen (see the first line in the sample outputs.)
  4. TODO 3 is in the get_drink_price() function. Generate one of 4 random numbers to be used in TODO 4.
  5. TODO 4 is below TODO 3. You need to write a series of if statements that use the random number from TODO 3 to select one of 4 random drink prices: $3.00, $3.75, $4.00, $4.50.
  6. TODO 5 is below TODO 4. Print the random drink price to the screen (see the second line in the sample outputs.)
  7. TODO 6 is in the bulk_discount() function. You should calculate the bulk discount as the square root of the total price. The total price is equal to the number of drinks * price of each drink. You will need to use Python's math module to make this calculation. Note that this function should return a decimal number for the discount. 25% = 0.25 discount
  8. TODO 7 is below TODO 6. Conditionally print a message to the screen. If the user buys at least 6 drinks and each drink costs at least $4, print a message to the user about how nice they are to their friends.
  9. TODO 8 is in the print_summary() function. Since the parameter discount is in the format 0.25 to be used in calculations, we need a new variable that contains 25 in order to print the receipt in a human-readable way.
  10. TODO 9 is below TODO 7. Round this to only 2 decimal places show when printing a number to the screen. So instead of something like 23.45666666667 printing, we want 23.45 (or 23.46). Essentially, we want all references to money to print with 2 decimal places (though trailing zeros may be missing).
  11. TODO 10. Bugs?! What? My code has bugs? Indeed it does. If you check out the receipt, the total after discount and savings are not correct. In print_summary, correct where the calculations are being made so that the summary reads properly.

Here are a couple sample runs of the program:

You're buying 5 drinks!
Each drink will cost $3.75.

****** CUSTOMER DISCOUNT SUMMARY ******
---------------------------------------
Total purchase amount:        $18.75
4.33% Discount:              -$0.81
---------------------------------------
TOTAL AFTER DISCOUNT          $17.94
---------------------------------------
You Saved                     $0.81
---------------------------------------

main.py:

# TODO 0: Import the functions from coffee.py into your main so that the errors go away in this file.

# DO NOT move the functions over into main.py. You should use imports so that the functions can stay in coffee.py

# Save the randomly generated number of drinks into the total_drinks variable

total_drinks = get_num_drinks()

# Save the randomly generated drink price into the total_drinks variable

cost_per_drink = get_drink_price()

# The purchase amount before discounts is the number of drinks * their price

overall_price = total_drinks * cost_per_drink

# Use purchase amount to calculate sale discount, save into variable

purchase_discount = bulk_discount(total_drinks, cost_per_drink)

# Pass the purchase amount and the discount to the print_summary function

print_receipt(overall_price, purchase_discount)

coffee.py:

# TODO 0: Import math and random, or just the functions you need from those modules

# get_num_drinks

# Parameters: none

# Return: should generate and return the number of drinks to order

# Side effect: should print the number of drinks

def get_num_drinks():

num_drinks = 0 # TODO 1: generate a random number between 2 and 12

print() # TODO 2: print how many drinks were ordered to the screen, in a full sentence.

return num_drinks

# get_drink_price

# Parameters: none

# Return: should choose and return one of four drink costs

# Side effect: should print the drink price

def get_drink_price():

drink_type = 0 # TODO 3: generate a random number representing the drink type

drink_price = 0

# TODO 4: write if-statements based on drink_type that will set drink_price to the appropriate value

print() # TODO 5: print the drink price to the screen, in a full sentence including $ and punctuation.

return drink_price

# bulk_discount

# Parameters: none

# Return: A discount equal to the square root of the

# total purchase amount, in decimal form.

# e.g. If the customer spend $25, this is a 5% discount, and should be returned as .05.

# Side effect: if the user buys at least six drinks, AND each drink costs at least $4, print "Wow, you must really like your friends!"

def bulk_discount(total_drinks, price_per_drink):

amount = 0.0 # TODO 6: calculate the square root of the purchased amount, using the math module. Remember to return the percentage as a decimal, e.g. .05 rather than 5.

# TODO 7: if the user buys at least six drinks, and each drink costs at least $4, print "Wow, your friends must really like you!"

return amount

# print_receipt

# Parameters: amount spent, discount

# Return: none

# Side effect: prints a summary of the customer's purchase and discount savings

def print_receipt(original_total, discount):

human_readable_discount = 0 # TODO 8: Generate the human-readable discount from the discount variable, e.g. .06 should be 6, to print a 6% discount

saved = original_total * discount

new_total = original_total - discount

# TODO 9: Fix the formatting of the summary below to print exactly 2 decimal places for each number

# TODO 10: Check the output and make sure that it makes sense. If not, it means there are bugs still in the code.

print("****** CUSTOMER DISCOUNT SUMMARY ******")

print("---------------------------------------")

print("Total purchase amount: \t\t $", original_total, sep="")

print(human_readable_discount, "% Discount: \t\t\t -$", saved, sep="")

print("---------------------------------------")

print("TOTAL AFTER DISCOUNT\t\t $", new_total, sep="")

print("---------------------------------------")

print("You Saved\t\t\t\t\t $", discount, sep="")

print("---------------------------------------")

In: Computer Science