Project 6-1: Email Creator
C++ code
Create a program that reads a file and creates a series of emails.
Console
Email Creator
================================================================
From: [email protected]
Subject: Deals!
Hi James,
We've got some great deals for you. Check our website!
================================================================
From: [email protected]
Subject: Deals!
Hi Josephine,
We've got some great deals for you. Check our website!
================================================================
From: [email protected]
Subject: Deals!
Hi Art,
We've got some great deals for you. Check our website!
Specifications
james\tbutler\[email protected]
josephine\tdarakjy\[email protected]
art\tvenere\[email protected]
To: {email}
From: [email protected]
Subject: Deals!
Hi {first_name},
We've got some great deals for you. Check our website!
-------------------
Text files
(email_template.txt)
To: {email}
From: [email protected]
Subject: Deals!
Hi {first_name},
We've got some great deals for you. Check our website!
email_list.txt
james butler [email protected]
josephine darakjy
[email protected]
art venere [email protected]
In: Computer Science
/**
* Loads a list of items from the given file. Each line is in the
format
* <item type>~<item data>. The createFromString()
methods in the item
* classes will be used to parse the item data.
* @param filename the filename
* @return the list of items
* @throws IOException if the file can't be opened
*/
public static List<Item> loadItems(String filename) throws
IOException {
List<Item> items = new ArrayList<>();
Scanner inPut = new Scanner(new FileReader(filename));
while(inPut.hasNextLine()) {
String line =
inPut.nextLine();
String [] tokens
= line.split(":");
String type =
tokens[0];
String data =
tokens[1];
items.add(type,data);
}
return items;
}
}
can you please check this line " items.add(type,data);" . I am having problem with it
In: Computer Science
USING MATLAB:
Using the data from table below fit a fourth-order polynomial to the data, but use a label for the year starting at 1 instead of 1872. Plot the data and the fourth-order polynomial estimate you found, with appropriate labels. What values of coefficients did your program find? What is the LMS loss function value for your model on the data?
| Year Built | SalePrice |
| 1885 | 122500 |
| 1890 | 240000 |
| 1900 | 150000 |
| 1910 | 125500 |
| 1912 | 159900 |
| 1915 | 149500 |
| 1920 | 100000 |
| 1921 | 140000 |
| 1922 | 140750 |
| 1923 | 109500 |
| 1925 | 87000 |
| 1928 | 105900 |
| 1929 | 130000 |
| 1930 | 138400 |
| 1936 | 123900 |
| 1938 | 119000 |
| 1939 | 134000 |
| 1940 | 119000 |
| 1940 | 244400 |
| 1942 | 132000 |
| 1945 | 80000 |
| 1948 | 129000 |
| 1950 | 128500 |
| 1951 | 141000 |
| 1957 | 149700 |
| 1958 | 172000 |
| 1959 | 128950 |
| 1960 | 215000 |
| 1961 | 105000 |
| 1962 | 84900 |
| 1963 | 143000 |
| 1964 | 180500 |
| 1966 | 142250 |
| 1967 | 178900 |
| 1968 | 193000 |
| 1970 | 149000 |
| 1971 | 149900 |
| 1972 | 197500 |
| 1974 | 170000 |
| 1975 | 120000 |
| 1976 | 130500 |
| 1977 | 190000 |
| 1978 | 206000 |
| 1980 | 155000 |
| 1985 | 212000 |
| 1988 | 164000 |
| 1990 | 171500 |
| 1992 | 191500 |
| 1993 | 175900 |
| 1994 | 325000 |
| 1995 | 236500 |
| 1996 | 260400 |
| 1997 | 189900 |
| 1998 | 221000 |
| 1999 | 333168 |
| 2000 | 216000 |
| 2001 | 222500 |
| 2002 | 320000 |
| 2003 | 538000 |
| 2004 | 192000 |
| 2005 | 220000 |
| 2006 | 205000 |
| 2007 | 306000 |
| 2008 | 262500 |
| 2009 | 376162 |
| 2010 | 394432 |
In: Computer Science
Programming Activity 7 - Guidance =================================
This assignment uses a built-in Python dictionary. It does not use a dictionary implementation from the textbook collections framework. It does not require any imports/files from the textbook collections framework. This week's "examplePythonDictionary.py" example uses a built-in Python dictionary. Note that the mode() function begins by creating an empty Python dictionary. You must use this dictionary in the following parts.
Part 1 ------ In this part you will add entries to the dictionary. Use a "for" loop to iterate through the values in the data list. For each value, use it as a dictionary key to see if it is already in the dictionary. If it is already in the dictionary, add one to that dictionary entries value. Each dictionary value contains the number of times that value occurs in the data. You reference the current value for a key via dictionary[key]. If it is not in the dictionary, add it by assigning an entry for it with a value of 1.
Part 2 ------ Python has a built-in max() function that finds the maximum in any iterable object. Use max() on the list of dictionary values to obtain the maximum number of times a value occurs. Assign this to a variable called maxTimes. You will make use of maxTimes in part 3.
Part 3 ------ Note that this part begins by creating an empty modes list. Use a "for" loop to loop through the dictionary keys. The default "for" iterator for a Python dictionary iterates through its keys. For each key, see if its associated dictionary value is equal to maxTimes. If it is equal, append that key to the modes list.
Part 4 ------ If no item in the data set is repeated, then your modes list at this point will be the same as your starting data list. However, this case actually should mean there is no mode. Actually, every item is a mode with a frequency of 1. But, we want to return an empty modes list for this case. If the modes list and the data list have the same length, reset modes to an empty list. Note that modes is already being returned at the end of the function.
=============================================================================================================================
useDictionary.py
# This program uses a Python dictionary to find the mode(s) of a data set.
# The mode of a data set is its most frequently occurring
value.
# A data set may have more than one mode.
# Examples:
# mode of [1,2,3,4,5,6,7] is none
# mode of [1,2,3,4,5,6,7,7] is 7
# modes of [1,2,2,2,3,3,4,5,6,7,7,7] are 2 and 7
# Replace any "<your code>" comments with your own code
statement(s)
# to accomplish the specified task.
# Do not change any other code.
# This function returns a list containing the mode or modes of
the data set.
# Input:
# data - a list of data values.
# Output:
# returns a list with the value or values that are the mode of
data.
# If there is no mode, the returned list is empty.
def mode(data):
dictionary = {}
# Part 1:
# Update dictionary so that each dictionary key is a value in data
and
# each dictionary value is the correspinding number of times that
value occurs:
# <your code>
# Part 2:
# Find the maximum of the dictionary values:
# <your code>
# Part 3:
# Create a list of the keys that have the maximum value:
modes = []
# <your code>
# Part 4:
# If no item occurs more than the others, then there is no
mode:
# <your code>
return modes
data1 = [1,2,3,4,5,6,7]
print(data1)
print("mode:", mode(data1))
print()
data2 = [1,2,3,4,5,6,7,7]
print(data2)
print("mode:", mode(data2))
print()
data3 = [1,2,2,2,3,3,4,5,6,7,7,7]
print(data3)
print("mode:", mode(data3))
print()
data4 = ["blue", "red", "green", "blue", "orange", "yellow",
"green"]
print(data4)
print("mode:", mode(data4))
print()
In: Computer Science
A chain of four matrices A1, A2, A3 and A4, with order 3 X 4, 4 X 2, 2 X 8 and 8 X 7 respectively. Deduce m[1, 4] to find best possible minimum number of multiplication
In: Computer Science
Room.java:
public class Room
{
// fields
private String roomNumber;
private String buildingName;
private int capacity;
public Room()
{
this.capacity = 0;
}
/**
* Constructor for objects of class Room
*
* @param rN the room number
* @param bN the building name
* @param c the room capacity
*/
public Room(String rN, String bN, int c)
{
setRoomNumber(rN);
setBuildingName(bN);
setCapacity(c);
}
/**
* Mutator method (setter) for room number.
*
* @param rN a new room number
*/
public void setRoomNumber(String rN)
{
this.roomNumber = rN;
}
/**
* Mutator method (setter) for building name.
*
* @param bN a new building name
*/
public void setBuildingName(String bN)
{
this.buildingName = bN;
}
/**
* Mutator method (setter) for capacity.
*
* @param c a new capacity
*/
public void setCapacity(int c)
{
this.capacity = c;
}
/**
* Accessor method (getter) for room number.
*
* @return the room number
*/
public String getRoomNumber()
{
return this.roomNumber;
}
/**
* Accessor method (getter) for building name.
*
* @return the building name
*/
public String getBuildingName()
{
return this.buildingName;
}
/**
* Accessor method (getter) for capacity.
*
* @return the capacity
*/
public int getCapacity()
{
return this.capacity;
}
}
Put the ideas into practice by extending the original Room class to create an AcademicRoom.java class.
In: Computer Science
I need to create a program that will simulate an ATM. The program has to be written in JAVA that uses JOptionaPane to pop up the messages. It will need to simulate to get
** balance
**withdraw
**Deposit
**exit the atm
** need to have a method that shows a receipt of everything that was done during the transaction
In: Computer Science
Create a program wages.py that assumes people are paid double time for hours over 60. They get paid for at most 20 hours overtime at 1.5 times the normal rate.
For example, a person working 65 hours with a regular wage of $10 per hour would work at $10 per hour for 40 hours, at 1.5 * $10 for 20 hours of overtime, and 2 * $10 for 5 hours of double time, for a total of
10*40 + 1.5*10*20 + 2*10*5 = $800.
The number of hours should be generated randomly between 35 and 75.
If the number of working hours is less than 40, display message “The salary cannot be generated” with sound of system bell as a warning.
In: Computer Science
I have one error and it encounters my split array and it should
output true or false
public class Main
{
private static int[] freq;
static boolean doubleOrNothing(int[] array, int size, int
i)
{
if (size <= 1)
return false;
if (2 * array[i] == array[i+1])
return true;
return doubleOrNothing(array, size - 1, i++);
}
/**
*
* @param word
* @param sep
*
*
* @param count
* @return
*/
public static String wordSeparator(String word, String sep, int
count)
{
if (count <= 0)
return "";
String new_word="";
if (count == 1)
return word;
return word + sep + wordSeparator(word, sep, count - 1);
}
static boolean mcNuggetNumber(int n) //checks for 3 or 7 piece
chicken nugget
{
boolean l = false, r = false;
if (n == 3 || n == 7)
return true;
if (n >= 3)
l = mcNuggetNumber(n - 3);
if (n >= 7)
r = mcNuggetNumber(n - 7);
return l || r;
}
static boolean splitArray(int arr[], int n, int k)
{
// An odd length array cannot be divided into pairs
if (n == 1)
return false;
// Create a frequency array to count occurrences
// of all remainders when divided by k.
// map freq = null;
// Count occurrences of all remainders
for (int i = 0; i < n; i++)
freq[arr[i] % k]++;
// Traverse input array and use freq[] to decide
// if given array can be divided in pairs
for (int i = 0; i < n; i++)
{
// Remainder of current element
int rem = arr[i] % k;
// If remainder with current element divides
// k into two halves.
if (2 * rem == k)
{
// Then there must be even occurrences of
// such remainder
if (freq[rem] % 2 != 0)
return false;
}
// If remainder is 0, then there must be two
// elements with 0 remainder
else if (rem == 0)
{
if (1 & freq[rem])
{
return false;
}
else
{
}
}
// Else number of occurrences of remainder
// must be equal to number of occurrences of
// k - remainder
else if (freq[rem] != freq[k - rem])
return false;
}
return true;
}
public static void main(String[] args) {
int a1[] ={1};
int a2[] = { 1,2 };
int a3[] = { 0,0,1 };
int a4[] = { 2,3,4 };
int a5[] = { 1,3,5,10 };
int a6[] = { 1,3,5,11 };
int a7[] = { 9,8,7,6,5,4,3,2,1 };
int a8[] = { 9,8,7,6,12,4,3,2,1 };
int i1[] = { 7 };
int i2[] = { 3,4 };
int i3[] = { 3,4,5 };
int i4[] = { 9,10,11 };
int o1[] = { 3,4 };
int o2[] = { 2,3,4 };
int o3[] = { 3,4,5,6 };
int o4[] = { 1,2,3,4,5,6 };
int s1[] = { 2, 2 };
int s2[] = { 2, 3 };
int s3[] = { 5, 2, 3 };
int s4[] = { 5, 2, 2 };
int s5[] = { 1, 1, 1, 1, 1, 1 };
int s6[] = { 1, 1, 1, 1, 1 };
int s8[] = { 1 };
int s9[] = { 3, 5 };
int s10[] = { 5, 3, 2 };
int s11[] = { 2, 2, 10, 10, 1, 1 };
int s12[] = { 1, 2, 2, 10, 10, 1, 1 };
int s13[] = { 1, 2, 3, 10, 10, 1, 1 };
System.out.println("Jones Robert ");
System.out.println("Assignment 3");
System.out.println("Recursion.");
System.out.println("All calls must result in true or
false.");
System.out.println();
System.out.println("Double Or Nothing." );
System.out.println("1. " + doubleOrNothing(a1, 1,0) );
System.out.println( "2. " + doubleOrNothing(a2, 2,0) );
System.out.println("3. " + doubleOrNothing(a3, 3,0) );
System.out.println("4. " + doubleOrNothing(a4, 3,0));
System.out.println("5. " + doubleOrNothing(a5, 4,0) );
System.out.println("6. " + doubleOrNothing(a6, 4,0) );
System.out.println("7. " + doubleOrNothing(a7, 9,0) );
System.out.println("8. " + doubleOrNothing(a8, 9,0) );
System.out.println();
System.out.println();
System.out.println("Word Separator.");
System.out.println("1. " + wordSeparator("Y", "X", 4));
System.out.println("2. " + wordSeparator("Y", "X", 2));
System.out.println("3. " + wordSeparator("Y", "X", 1));
System.out.println("4. " + wordSeparator("Y", "X", 0));
System.out.println();
System.out.println("McNugget Numbers" );
System.out.println(" 1. " + mcNuggetNumber(0));
System.out.println(" 2. " + mcNuggetNumber(1) );
System.out.println(" 3. " + mcNuggetNumber(2) );
System.out.println(" 4. " + mcNuggetNumber(3) );
System.out.println(" 5. " + mcNuggetNumber(4) );
System.out.println(" 6. " + mcNuggetNumber(5) );
System.out.println(" 7. " + mcNuggetNumber(6) );
System.out.println(" 8. " + mcNuggetNumber(7) );
System.out.println(" 9. " + mcNuggetNumber(8) );
System.out.println("10. " + mcNuggetNumber(9) );
System.out.println("11. " + mcNuggetNumber(10) );
System.out.println("12. " + mcNuggetNumber(11) );
System.out.println("13. " + mcNuggetNumber(12) );
System.out.println("14. " + mcNuggetNumber(13));
System.out.println("15. " + mcNuggetNumber(14));
System.out.println("16. " + mcNuggetNumber(15));
System.out.println("17. " + mcNuggetNumber(16));
System.out.println();
System.out.println ("Split the Array");
System.out.println ("1. " + splitArray (1));
System.out.println ("2. " + splitArray (2));
System.out.println ("3. " + splitArray (3));
System.out.println ("4. " + splitArray (4));
System.out.println ("5. " + splitArray (5));
System.out.println ("6. " + splitArray (6));
System.out.println ("7. " + splitArray (7));
System.out.println ("8. " + splitArray (8));
System.out.println ("9. " + splitArray (9));
System.out.println ("10. " + splitArray (10));
System.out.println ("11. " + splitArray (11));
System.out.println ("12. " + splitArray (12));
System.out.println ("13. " + splitArray (13));
System.out.println ("14. " + splitArray (14));
System.out.println ("15. " + splitArray (15));
System.out.println ("16. " + splitArray (16));
System.out.println();
}
private static String splitArray(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To
change body of generated methods, choose Tools | Templates.
}
}
I have an error
In: Computer Science
Consider the following schema:
Suppliers(sid, sname, address)
Parts(pid, pname, color)
Catalog(sid, pid, cost)
In a plain text file, write the following queries in SQL:
1.Find the names of all suppliers who supply a green part.
2.Find the names of all suppliers who are from Illinois.
3.Find the names of all suppliers who sell a red part costing less than $100.
4.Find the names and colors of all parts that are green or red.
In writing these (basic) queries you may make the following assumptions:
a. Each part has only
one color.
b. The cost field is a real number with two decimal places (e.g.,
100.25, 93.00).
c. The sid field in Suppliers and the sid field in Catalog refer to
the same field.
d. The pid field in Parts and the pid field in Catalog refer to the
same field.
In: Computer Science
Convert the following decimal number to eight (8) binary bits: 21, 200, 105, 144, 183, 199, 88, 100, 19, 204
In: Computer Science
Question:
Write a program in python that reads in the file climate_data_2017_numeric.csv and prompts the user to enter the name of a field (other than Date), and then outputs the highest and lowest values recorded in that field for the month of August.
The file climate_data_2017_numeric.csv contains the following fields:
Expected print out output (Make sure your output looks exactly like the output shown):
Note: there are 2 space in front of the last line.
Available field names:
Minimum temperature (C)
Maximum temperature (C)
Rainfall (mm)
Speed of maximum wind gust (km/h)
9am Temperature (C)
9am relative humidity (%)
3pm Temperature (C)
3pm relative humidity (%)
Please enter a field name: Minimum temperature (C)
Statistics for field 'Minimum temperature (C)':
Min: 1.0 Max: 14.6
Dataset:
https://docs.google.com/spreadsheets/d/1MjyOSUrm2Nazo9vpan_4E6fAhQlr8Ok2PXu9c8syXqY/edit?usp=sharing
In: Computer Science
create a genetic algorithm for knapsack problem in c++
In: Computer Science
C++ requirements
All values must be read in as type double and all calculations need to be done using type double.
For part 2 you MUST have at least 4 functions, including main. The main function will be the driver of the program. It needs to either do the processing or delegate the work to other functions.
Failure to follow the C++ requirements could reduce the points received from passing the tests.
General overview
This program will convert a set of temperatures from Fahrenheit to Celsius.
Your program will be reading in three double values. The first values are starting and ending temperatures. The third value is the increment value. There is no prompt for the input. There is an error message that can be displayed. This is discussed later.
You need to display output for all of the values between the starting and ending values. First two values are temperatures in Fahrenheit. You need to display all of the values from the first temperature to the last temperature. You increment from one temperature to the next by the increment value (the third value you read in). You need to convert these temperatures to Celsius. You need to output the temperatures as both Fahrenheit and Celsius. The numbers should be 15 characters wide with 3 digits of precision and need to be in fixed format. Do not use tab characters (\t) to output the values.
For part 2 you MUST have at least 4 functions, including main. The main function will be the driver of the program. It needs to either do the processing or delegate the work to other functions.
Obviously the main function will have the same function that you have been using for all of your labs. In addition to need to have a function with the following signature:
double convert(double fahrenheit)
Other functions that you may want to have are:
A function to read in the values
A display function
A display heading function
The headings are also required (see the sample output below).
The conversion from Fahrenheit to Celsius is:
celsius = (fahrenheit - 32) / 1.8
Here is a sample run with valid input:
-30 100 20
The output would be:
Fahrenheit Celsius
-30.000 -34.444
-10.000 -23.333
10.000 -12.222
30.000 -1.111
50.000 10.000
70.000 21.111
90.000 32.222
For data validation you need to make sure the first number read in is less than or equal to the second number. The third number read in must be greater than 0. If this is not the case you need to output the following message and read in three new values:
Starting temperature must be <= ending temperature and increment must be > 0.0
The above message is all one line of output.
You need to keep reading in values and outputting messages until the values are all valid.
Using the following input :
40 30 5 30 40 -5 30 40 5
We get the output:
Starting temperature must be <= ending temperature and increment must be > 0.0
Starting temperature must be <= ending temperature and increment must be > 0.0
Fahrenheit Celsius
30.000 -1.111
35.000 1.667
40.000 4.444
Depending on the value for the increment the ending temperature may not be reached. You need to display the temperatures where the value of the Fahrenheit temperature is less than or equal to the ending temperature.
Consider this input:
100.5 110.4 5
The valid output will be:
Fahrenheit Celsius
100.500 38.056
105.500 40.833
The last Fahrenheit temperature output is 105.5. The next one would have been 110.5, but this is more than the ending temperature of 100.4. This is not an error condition. The output would be as above.
Think about what other tests cases are needed? Do we cover all possible input problems or valid types of input values?
Expected output
There are eight tests. Each test will have a new set of input data. You must match, exactly, the expected output.
You will get yellow highlighted text when you run the tests if your output is not what is expected. This can be because you are not getting the correct result. It could also be because your formatting does not match what is required. The checking that zyBooks does is very exacting and you must match it exactly. More information about what the yellow highlighting means can be found in course "How to use zyBooks" - especially section "1.4 zyLab basics".
Finally, do not include a system("pause"); statement in your program. This will cause your verification steps to fail.
In: Computer Science
I have a recursive Tower of Hanoi program and would like to get the index numbers to be in correct sequence: 1,2,3,4,5,6,7. How can I do this?
Main.java
import java.io.*;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
/**There is a stack of N disks on the first of three poles (call them A, B and C) and your job is to move the disks from pole A to pole C without ever putting a larger disk on top of a smaller disk.*/
System.out.println("\nW7L1 Tower of Hanoi");
System.out.println("Program by Quang Pham\n");
char startingrod = ' ';
char endingrod = ' ';
Scanner sc = new Scanner(System.in);
System.out.println("Enter the starting rod letter (A, B, or C).");
startingrod = sc.next().charAt(0);
System.out.println("Enter the ending rod letter (A, B, C).");
endingrod = sc.next().charAt(0);
if (startingrod == endingrod)
{
System.out.println("Sorry. Starting rod and ending rod cannot be the same.");
System.out.println("Enter ending rod letter (A, B, C)");
endingrod = sc.next().charAt(0);
}
else if ((startingrod=='A' && endingrod=='C')||(startingrod=='C' && endingrod=='A'));
{
char other = (char)('A' + 'B' + 'C' - startingrod - endingrod) ;
System.out.println("OK. Starting with disks 1, 2, 3, on rod " + startingrod + "." + "\n");
System.out.println("Moves are as follows:");
int count = playHanoi (3,startingrod,other,endingrod);
System.out.println();
System.out.printf("All disks 1, 2, 3 are on rod %c.\n", endingrod);
System.out.println("All done.");
System.out.println("Took a total of " + count + " moves.");
sc.close();
System.out.println();
}
}
private static int playHanoi( int n, char from , char other, char to)
{
int index = 1;
int count = 1;
if (n == 0)
return 0;
else if(n == 1)
{
System.out.printf("%d.", index);
System.out.printf(" Move disk "+ n +" from rod %c to rod %c \n", from, to);
index++;
return count;
}
else
{
count+= playHanoi(n - 1, from, to, other);
System.out.printf("%d.", index);
System.out.printf(" Move disk " + n + " from rod %c to rod %c \n", from, to);
index++;
count+= playHanoi(n - 1, other, from, to);
index++;
return count;
}
}
}
The program is at: https://repl.it/@quangnvpham1/W7L1-Recursive-Tower-of-Hanoi-Program#Main.java .
Any help with this problem is greatly appreciated. Yours truly, Quang Pham
In: Computer Science