In: Computer Science
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 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:
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:
In: Computer Science
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 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. 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 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
Write your version of the find command and add comments.
In: Computer Science
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 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]
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 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
In: Computer Science
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
In: Computer Science
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 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.
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