Draw a (single) tree T, such that
• Each internal node of T stores a single character;
• A preorder traversal of T yields: E K D M J G I A C F H B L;
• A postorder traversal of T yields: D J I G A M K F L B H C E.
Part2
Let T be an ordered tree with more than one node. Is it possible that the preorder traversal of T visits the nodes in the same order as the post order traversal of T ? If so, give an example. If not, then explain why this cannot occur.
In: Computer Science
Why do we need a TCP/IP-OSI hybrid (5) model, when we already have the TCP/IP model?
In: Computer Science
write an algorithm and python program using the following information. also can y
How much should I study outside of class?
Issue:
Your fellow students need help. This is their first year in college and they need to determine how many hours they need to study to get good grades.
Study Hours Per Week Per Class Grade
15 A
12 B
9 C
6 D
0 F
Project Specifications:
Name: FirstName LastName
Credits: 12
Study Hours: 60
Grade: A
Total Students: 3
Average Credits: 9
Average Study Hours: 20
ou please run the program?
In: Computer Science
Background:
You can create a simple form of encryption using
the xor Boolean operator. For example, if you want
to encrypt the letter 'A':
Your
task:
Write a C++ program that meets the following requirements:
Submit:
Documentation should include:
In: Computer Science
JAVA CODE
Define a method called changeGroupPrice that could be added to the definition of the class Purchase. This method has one parameter that is of type double, and is named salePercent. This number represents the percent reduction in the groupPrice amount. The method uses this number to change the groupPrice. The code of the method should check to make sure the range of salePercent is between 0 and 50%. If it is, the groupPrice should be adjusted accordingly. If the salePercent is out of range of the accepted values an error message should be printed and the program terminated.
public class PurchaseDemo
{ public static void main(String[] args)
{
Purchase oneSale = new Purchase();
oneSale.readInput();
oneSale.writeOutput();
System.out.println("Cost each $" + oneSale.getUnitCost());
System.out.println("Total cost $" + oneSale.getTotalCost());
}
}
import java.util.Scanner;
/**
Class for the purchase of one kind of item, such as 3
oranges.
Prices are set supermarket style, such as 5 for $1.25.
*/
public class Purchase
{
private String name;
private int groupCount; //Part of a price, like the 2 in //2 for
$1.99.
private double groupPrice; //Part of a price, like the $1.99
// in 2 for $1.99.
private int numberBought; //Number of items bought.
public void setName(String newName)
{
name = newName;
}
/**
Sets price to count pieces for $costForCount.
For example, 2 for $1.99.
*/
public void setPrice(int count, double costForCount)
{
if ((count <= 0) || (costForCount <= 0))
{
System.out.println("Error: Bad parameter in " +
"setPrice.");
System.exit(0);
}
else
{
groupCount = count;
groupPrice = costForCount;
}
}
public void setNumberBought(int number)
{
if (number <= 0)
{
System.out.println("Error: Bad parameter in " +
"setNumberBought.");
System.exit(0);
}
else
numberBought = number;
}
/**
Reads from keyboard the price and number of a purchase.
*/
public void readInput()
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter name of item you are purchasing:");
name = keyboard.nextLine();
System.out.println("Enter price of item as two numbers.");
System.out.println("For example, 3 for $2.99 is entered as");
System.out.println("3 2.99");
System.out.println("Enter price of item as two numbers, " +
"now:");
groupCount = keyboard.nextInt();
groupPrice = keyboard.nextDouble();
while ((groupCount <= 0) || (groupPrice <= 0))
{ //Try again:
System.out.println("Both numbers must " +
"be positive. Try again.");
System.out.println("Enter price of " +
"item as two numbers.");
System.out.println("For example, 3 for " +
"$2.99 is entered as");
System.out.println("3 2.99");
System.out.println(
"Enter price of item as two numbers, now:");
groupCount = keyboard.nextInt();
groupPrice = keyboard.nextDouble();
}
System.out.println("Enter number of items purchased:");
numberBought = keyboard.nextInt();
while (numberBought <= 0)
{ //Try again:
System.out.println("Number must be positive. " +
"Try again.");
System.out.println("Enter number of items purchased:");
numberBought = keyboard.nextInt();
}
}
/**
Displays price and number being purchased.
*/
public void writeOutput()
{
System.out.println(numberBought + " " + name);
System.out.println("at " + groupCount +
" for $" + groupPrice);
}
public String getName()
{
return name;
}
public double getTotalCost()
{
return (groupPrice / groupCount) * numberBought;
}
public double getUnitCost()
{
return groupPrice / groupCount;
}
public int getNumberBought()
{
return numberBought;
}
}
In: Computer Science
For this assignment I need to use information from a previous assignment which I will paste here:
#ifndef TODO
#define TODO
#include <string>
using std::string;
const int MAXLIST = 10;
struct myToDo
{
string description;
string dueDate;
int priority;
};
bool addToList(const MyToDo &td);
bool addToList(string description, string date, int
priority);
bool getNextItem(MyToDo &td);
bool getNextItem(string &description, string &date, int
&priority);
bool getByPriority(MyToDo list[], int priority int
&count);
void printToDo();
#endif
#include <iostream>
#include "ToDo.h"
using namespace std;
myToDo ToDoList[MAXLIST];
int head = 0, tail = -1;
bool addToList(const myToDo &td)
{
if(head < MAXLIST)
{
if(tail ==
-1)
tail++;
ToDoList[head] =
td;
head++;
return true;
}
return false;
}
bool addTolist(string description, string date, int priority)
{
MyToDo td;
td.description = description;
td.dueDate = date;
td.priority = priority;
return addToList(td);
}
bool getNextItem(MyToDo &td)
{
if(tail >= 0)
{
if(tail >=
MAXLIST)
tail
= 0;
td =
ToDoList[tail];
tail++;
return true;
}
return false;
}
bool getNextItem(string &description, string &date,
int&priority)
{
myToDo tmp;
bool status = getNextItem(tmp);
if(status == true)
{
description =
tmp.description;
date =
tmp.dueDate;
priority =
tmp.priority;
}
return status;
}
bool getByPriority(MyToDo list[], int priority, int
&count)
{
if(tail < 0)
return
fals;
count = 0;
for(int i = 0; i
< head; i++)
{
if(ToDoList[i].priority
== priority)
{
list[count]
= ToDoList[i];
count++;
}
}
if(count > 0)
return
true;
return false;
}
void printToDo())
{
for(int i = 0; i < head; i++)
{
cout <<
"Description" << ToDoList[i].description << endl;
cout << "Due
Date" << ToDoList[i].dueDate << endl;
cout <<
"Priority" << ToDoList[i].priority << endl;
}
With this info I am asked:
Creating A Classes
This assignment is geared to check your understanding of Object Oriented Programming and class creationg. The class type is called a complex type because it is a type that you create from the primitive types of the language. Even though you create it it is still a full fledged type.
This activity is designed to support the following Learning Objective:
Instructions
In Assignment 19 you created a simple ToDo list that would hold structs that contained information about each item that would be in the list.. For this assignment I want you to take lab 19 an create a class out of it.
Your class should be called ToDoList. The definition for the ToDoList should be in the header file. The variables that make up the data section should be put in the private area of the class. The prototypes for the interface functions should be in the public area of the class.
Data Section
You can easily identify the variables that make up the data section from the fact that all of the functions use these variables. You should remember from the lecture material on classes that the data section should be the private section of the class. You should also note that if a variable should not have direct access to it then it should be in the private section. What I mean here is that if a person can directly access a variable from a function outside of the class and if modifying this variable can cause unknown problems to the operation of your class then it should be in the private section of the class.
Prototype Functions
All of the function prototypes should also go in the class. If a function is an interface into the class then it should go in the public section. For this assignment all functions are interfaces so all prototypes should go in the public section of the class.
In the previous step you prototyped all of the functions and put them in the public section of the class definition. The bodies for these functions should go in ToDoList.cpp. Don't forget to use the scope resolution operator to relate the function bodies to the prototypes in the class definition.
Constructors
You should have a default and overloaded constructors. The overloaded constructor should take 2-strings and an int which represent the descrition, dueDate, and priority.
In: Computer Science
Information Systems Business
Risks"
Identify the risks related to information systems and
suggest ways to minimize them.
Describe Quality Assurance and Quality Control.
Discuss their roles in information systems.
In: Computer Science
WRITE IN PERL
Creating a Perl Product Directory - A product "id" will be used to identify a product (the key) and the description will be stored as the value
Here is a template:
#!/usr/bin/perl
use warnings;
%products = (); # empty hash to store products in
sub getChoice(){
print("Welcome to the Product Directory\n");
print("1. Add a Product to Directory\n");
print("2. Remove a Product from Director\n");
print("3. Lookup a Product in Directory\n");
print("4. List all products\n");
print("5. Quit\n");
print("Enter your option: ")
chomp($choice = <STDIN>);
return $choice
}
$c = getChoice();
while($c ne "5"){
if($c eq "1"){
# Ask the user to enter input for a product's ID
# Ask the user to enter input for a product's description
# Add the item to the hash with the supplied ID as the key and
description as the value
}
# Options 2 - 4
}
In: Computer Science
PYTHON
Generates a list of datetimes given a list of dates and a list of times. All possible combinations of date and time are contained within the result. The result is sorted in chronological order.
For example,
Input:
>>> timetable([date(2019,9,27), date(2019,9,30)],
[time(14,10), time(10,30)])
Output:
[datetime(2019,9,27,10,30), datetime(2019,9,27,14,10),
datetime(2019,9,30,10,30), datetime(2019,9,30,14,10)]
Current code:
from datetime import date, time, datetime
def timetable(dates, times):
lis = []
for c in times:
for y in dates:
x = f"(datetime{y},{c})"
lis.append(x)
#doesn't work at all
In: Computer Science
Write a program that inputs the values of three Boolean variables, a, b, and c, from a “cin” operator (user gives the values be sure to prompt user for what they have to give!). Then the program determines the value of the conditions that follow as true or false. 1. !(a&&b&&c) && ! (a||b||c) 2. !(a||b)&&c Output should include the values of a,b,c ie 0 or 1 in the patterns that follow reflecting the Boolean logic being tested. Where “True” or “False” are in string variables. Study this example! for input of a=1 and b =0 and c=1 results in output looking like !( 1&&0&&1) && !(1|| 0||1) is False !(1||0)&&1 is False Run for the eight cases of a,b,c in Table 3.2 (both editions of text) Warning follow this output example format else you will have to redo it! Hint: your output statements will be large! Hint:. you have to use strings and variables for parts like<< “!(<
In: Computer Science
Write a program that concatenates the characters in a
two-dimensional into a set of Strings in a
one-dimensional array as described below.
main
#Request and Read in the number of rows of a two dimensional
array.
#Create the reference to the two-dimensional array.
For each row
#Request and Reads in a line of text
#Based on the length of the line create a row with the correct
number of columns (look
#back to lesson 3)
#Place each character for the String into the row, one character at
a time.
#Call concatenateColumnsPerRow with a reference to the character
two-dimensional array as a
#reference. The return will be a reference to a one-dimensional
String array.
#Call displayArray with a reference to the one-dimensional
StringArray.
concatenateColumnsPerRow
#Accepts a character two-dimensional array reference as
input.
#Concatenates the elements in each row into a String.
#Returns a one-dimensional String array, with the Strings from each
row placed into the
#corresponding row in the String array.
displayArray
#Accepts the one-dimensional String array and prints out the
Strings on separate lines
In: Computer Science
Hi i need a c++ program that can convert charactor into numbers
pseodocode
user input their name
for example john
every single charactor should have a value so it return correct result
eg:
j=2, o=1, h=7,n=2
and display these numbers
if you may need any question to ask me, i will be very happy to answer them.
Thanks!
example project close but not accurate
#include<iostream>
#include<string>
#include<exception>
#include <cstdlib>
#include<stdio.h>
#include<map>
#include <cctype>
#include<Windows.h>
#define INPUT_SIZE 8
using namespace std;
// Function to reverse a string
void reverseStr(string& str)
{
int n = str.length();
// Swap character starting from two
// corners
for (int i = 0; i < n / 2; i++)
swap(str[i], str[n - i - 1]);
}
int main() {
const std::string alpha =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
std::string text;
std::cin >> text;
// convert all lower case characters to upper
case
for (char& c : text) c = std::toupper(c);
// sum up the values of alpha characters ('A' == 1,
'B' == 2 etc.)
int sum = 0;
for (char& c : text) // for each character c in
text
{
// locate the character in
alpha
//
http://www.cplusplus.com/reference/string/string/find/
const auto pos = alpha.find(c);
if (pos != std::string::npos) //
if found (if the character is an alpha character)
// note:
non-alpha characters are ignored
{
const int value
= pos + 1; // +1 because position of 'A' is 0, value of 'A' is
1
sum +=
value;
cout <<
sum;
}
}
In: Computer Science
The following pieces of information need to be stored in variables. List the best data types to use for the variables.
|
Information to store |
Best data type |
|
Street address |
|
|
Average rainfall |
|
|
Machine error count |
In: Computer Science
This C++ program is to validate the ISBN number and
output "Valid" if the number is valid, and "Invalid"
otherwise.
The ISBN number for a book is a 10-digit number made up of 4
sections separated by '-'. In the ISBN
number 1-214-02031-3:
1 represents a country (must be 1 digit)
214 represents the publisher (must be 3 digits)
02031 represents the book number (must be 5 digits)
3 is the checksum (must be 1 digit or the letter 'x').
The checksum is a digit to see if the ISBN number is a valid
number. If the checksum is 'x', then that
represents the digit 10.
A weight is associated with each digit:
10 with the first digit (1 in the example)
9 with the second digit (2 in the example)
8 with the 3rd digit (1 in the example)
7 with the 4th digit (4 in the example)
6 with the 5th digit (0 in the example)
5 with the 6th digit (2 in the example)
4 with the 7th digit (0 in the example)
3 with the 8th digit (3 in the example)
2 with the 9th digit (1 in the example)
1 with the 10th digit (3 in the example)
To check to see if an ISBN number is valid, you multiply the digit
by its weight and add the resulting
products. If the sum is evenly divisible by 11, then it is a valid
ISBN number.
In the example: 1-214-02031-3
1*10+2*9+1*8+4*7+0*6+2*5+0*4+3*3+1*2+3*1 = 88
Since 88 is evenly divisible by 11, the above number is a valid
ISBN number.
The main function will create an array of pointers of type char
to store all the ISBN numbers I'll give
you in a separate text file for the convenience of copying. The
main should iterate over that array and for
each ISBN number call the function checkDigits which will return
true is there are digits and a correct
number of digits in each section, and if each section is separated
by a '-'. Otherwise, it will return false.
If checkDigits returns true, the main will call checkSum, which
will return true if the sum of the
products of the weights and digits is divisible by 11. Otherwise,
it returns false. The main program will
output "valid" or "not valid" for each ISBN number.
In this program, do not use subscripted variables. Use
the pointers to the characters. The declaration for
the checkSum would be:
bool checkSum(char *);
Note that functions take a single pointer as a parameter, not a
char ** (i.e. array of pointers).
Note, that *(ptrISBN + 3) is the same as ptrISBN[3]
To check to see if there is an '-' in the i-th position you can use
the statement:
if(*(ptrISBN + i) == '-')
Your program should not be like that:
if(ISBN[0] == '-' || ISBN[1] == '-' || ISBN[2] == '-' ….. ||
ISBN[10] == '-')
To check for each element in the array.
I want you to use the loop and iterate over the arrays using the
loop.
However, if you need to check just a couple (maybe three, max),
that is OK.
Should use:
2 functions with using const arguments
Using enum valid, invalid in place of bool
Do not use:
Declaring array according to standards
off-by-one errors
Using global variables
Run the program with the data from the data file
“test_data.txt”
Note, I want you to hard code the array of pointers. I don't want
you to read the data from the file on
the fly.
------------------------------------------------------------------------------------------------------------------------------------------------------------
Expected output would be similar to the following:
Input ISBN numbers:
(input number from given .txt file)
Array filled! //use a loop to get input from the user
Checking ISBN numbers...
//(for ISBN #'s return False/Invalid)
Invalid ISBN #
//(for ISBN #'s return True/Valid)
Checking sum of Valid ISBN numbers
Valid/Invalid ISBN # : (return sum of ISBN number)
------------------------------------------------------------------------------------------------------------------------------------------------------------
Given text file: Note, I want you to hard code the array
of pointers. I don't want you to read the data from the file
on
the fly. IF applicable/possible try to make another function to
show the difference.
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
write a function that accept an array and its size than return an array call modeAry that store the following information: modeAry[0] = Number of modes; modeAry[1] = Frequency of the modes ; modeAry[>=2] = All the modes you found ; EXP:if the array input is [1,1,2,2,4,3,3], the function modAry should be [3,2,1,2,3]. In c++
In: Computer Science