In: Computer Science
Develop a program to maintain a Linked List of homework assignments name and due date. When an assignment is assigned, add it to the list, and when it is completed, remove it. You should keep track of the due date. Your program should provide the following services each contained within its own method:
-The commands are input from the user keyboard as well as the Assignment Names and the Assignment Due Dates. All entered by the user.
-Coded with comments
In: Computer Science
Code is only reading the last line from the text files. How would I resolve? This is for the Name Search problem in Starting out with Python book. def main(): #open a file for reading infile = open('GirlNames.txt' , 'r') #Read the contents into a list Girls = infile.readlines() #open another file for reading infile = open('BoyNames.txt', 'r') #Read the contents into a lits Boys = infile.readlines() #Get a name to search for Name = input('Enter a name: ') #Determine if name is in list if Name in Girls or Name in Boys: print( Name, "is one of the popular names.") else: print(Name, "was not found in the list.") main()
In: Computer Science
During the audit of derivatives, investments, and hedges, a
number of misstatements were detected by the auditor. For each
misstatement, select from List I the assertion affected by the
misstatement. Select from List II the audit procedure that most
likely detected the misstatement. Each choice may be used once,
more than once, or not at all.
List 1
List 2
1. Confirm securities and other assets held by third parties.
2. Obtain and review minutes of meetings of those charged with governance.
3. Obtain prices at year end from an independent source and compare with recorded amounts.
4. Inspect securities on hand.
5. Read and evaluate available contracts for effects on the financial statements.
6. Review the financial statements and inquire of management about investments and derivatives.
|
Misstatement |
List I - assertion affected |
List II - audit procedure used to detect misstatement |
|
1. A derivative used as a fair value hedge was reported at less than fair value. |
||
|
2. A contract for a future delivery of a commodity used as a hedge was not clearly described in the notes to the financial statements. |
||
|
3. A contract approved by the board of directors creating and defining a derivative was not recorded in the financial statements. |
||
|
4. A cash flow hedge created to protect against an interest rate increase was ineffective and resulted in a loss that was unrecognized in the current year. |
||
|
5. A derivative security being reported at year end had been sold by the client’s broker earlier in the year. |
In: Accounting
// This program demonstrates a Binary Search
//PLACE YOUR NAME HERE
#include<iostream>
using namespace std;
int binarySearch(int [], int, int); // function prototype
const int SIZE = 16;
int main()
{
int found, value;
int array[] = {34,19,19,18,17,13,12,12,12,11,9,5,3,2,2,0}; // array to be searched
cout << "Enter an integer to search for:" << endl;
cin >> value;
found = binarySearch(array, SIZE, value); //function call to perform the binary search
//on array looking for an occurrence of value
if (found == -1)
cout << "The value " << value << " is not in the list" << endl;
else
{
cout << "The value " << value << " is in position number "
<< found + 1 << " of the list" << endl;
}
return 0;
}
//*******************************************************************
// binarySearch
//
// task: This searches an array for a particular value
// data in: List of values in an orderd array, the number of
// elements in the array, and the value searched for
// in the array
// data returned: Position in the array of the value or -1 if value
// not found
//
//*******************************************************************
int binarySearch(int array[],int numElems,int value) //function heading
{
int first = 0; // First element of list
int last = numElems - 1; // last element of the list
int middle; 0 // variable containing the current
// middle value of the list
while (first <= last)
{
middle = first + (last - first) / 2;
// write statement to determine if value is in the middle, then we are done
else if (array[middle]<value)
last = //what would the last be? // toss out the second remaining half of
// the array and search the first
else
first = //what would the first be? // toss out the first remaining half of
// the array and search the second
}
return -1; // indicates that value is not in the array
}
In: Computer Science
python
Write a function pack_to_5(words) that takes a list of string objects as a parameter and returns a new list containing each string in the title-case version. Any strings that have less than 5 characters needs to be expanded with the appropriate number of space characters to make them exactly 5 characters long. For example, consider the following list:
words = ['Right', 'SAID', 'jO']
The new list would be:
['Right', 'Said ', 'Jo ']
Since the second element only contains 4 characters, an extra space must be added to the end. The third element only contains 2 characters, so 3 more spaces must be added.
Note:
For example:
| Test | Result |
|---|---|
words = ['Right', 'SAID', 'jO'] result = pack_to_5(words) print(words) print(result) |
['Right', 'SAID', 'jO'] ['Right', 'Said ', 'Jo '] |
words = ['help', 'SAID', 'jO', 'FUNNY'] result = pack_to_5(words) print(words) print(result) |
['help', 'SAID', 'jO', 'FUNNY'] ['Help ', 'Said ', 'Jo ', 'Funny'] |
result = pack_to_5([]) print(result) |
[] |
In: Computer Science
Write a method, twoSumSorted2, that solves the following variant of the Two-Sum problem:
Given a sorted array of integers where each element is unique and a target integer, return in an Array List, the indices of all pairs of elements that sum up to the target. Each pair of indices is also represented as an Array List (of two elements). Therefore, the method returns an Array List of an Array List of size 2. If no pair in the input array sums up to the target, then the method should return an empty list.
public class Hw2_p1 {
// HW2 Problem 1 Graded Method
public static
ArrayList<ArrayList<Integer>> twoSumSorted(int[] A, int
target) {
ArrayList<ArrayList<Integer>> ans = new
ArrayList<>();
// Your code starts
// Your code ends
return ans;
}
// Test driver for twoSumSorted2
public static void main(String[] args) {
}
}
The following are two sample runs:
Input: ? = [−7, −5, −2, 0, 1, 6, 7, 8, 9], ?????? = 1
Return value: [0,7], [1, 5], [3, 4]
Explanation: The pairs in the input array that sum up to 1 are [−7, 8], [−5, 6] and [0, 1]. Their indices are [0, 7], [1, 5] and [3, 4] respectively.
Input: ? = [−2, 0, 1, 6, 7, 8], ?????? = 3
Return value: [ ]
Explanation: No pair of elements in input array sums up to 3. The returned list is thus empty.
Your method must have time complexity ?(?), where ? is the length of the input array.
In: Computer Science
create code for deletestudentbyID Number for choice ==
4
package courseecom616;
import java.util.Scanner;
import java.util.ArrayList;
public class CourseeCOM616 {
private String courseName;
private String[] studentsName = new
String[1];
private String
studentId;
private int numberOfStudents;
public CourseeCOM616(String courseName) {
this.courseName =
courseName;
}
public String[] getStudentsName() {
return
studentsName;
}
public int getNumberOfStudents() {
return
numberOfStudents;
}
public String getStudentId() {
return studentId;
}
public void setStudentID(int studentID)
{
this.studentId =
studentId;
}
public String getCourseName(){
return courseName;
}
public void addStudent(String student) {
if (numberOfStudents ==
studentsName.length) {
String[] a = new String[studentsName.length + 1];
for (int i = 0; i < numberOfStudents; i++) {
a[i] = studentsName[i];
}
studentsName = a;
}
studentsName[numberOfStudents] = student;
numberOfStudents++;
}
public String[] addStudentByIndex(String
student, int index) {
String[] a = new
String[studentsName.length + 1];
if (numberOfStudents ==
studentsName.length) {
for (int i = 0; i < a.length; i++) {
if (i < index) {
a[i] = studentsName[i];
} else if (i == index) {
a[i] = student;
} else {
a[i] = studentsName[i - 1];
}
}
}
numberOfStudents++;
return a;
}
public static void display(String[] students)
{
System.out.println("========================");
System.out.print("Now
the New students Array is : \n");
for (int i = 0; i <
students.length; i++) {
System.out.println("Index: " + (i) + "--> " + students[i] + "
");
}
}
public void dropStudent(String student) {
int index = findStudent(student);
if (index >= 0) {
dropStudent(index);
}
else {
System.out.println(student + " is not in
the course: " + courseName);
}
}
private void dropStudent(int index)
{
String[] s = new
String[studentsName.length - 1];
for (int i = 0, j = 0; i < s.length;
i++, j++) {
if (i == index) {
j++;
}
s[i] = studentsName[j];
}
this.studentsName = s;
numberOfStudents--;
}
public String[] removeStudentByIndex(String[] a,
int index) {
String[] b = new
String[a.length - 1];
studentsName = a;
for (int i = 0, k = 0; i
< a.length; i++) {
if (i == index) {
continue;
} else {
b[k++] = a[i];
}
}
numberOfStudents--;
return b;
}
public String[] deleteStudentByID(String[] a,
int id) {
public String [] deleteStudentByName (String
students1 [], String name) {
String[] b = new
String[students1.length - 1];
for (int i = 0, k = 0; i
< students1.length; i++) {
if (students1[i].equals(name)) {
continue;
} else {
b[k++] = students1[i];
}
}
numberOfStudents--;
return b;
}
{
this.studentId =
studentId;
this.studentsName =
studentsName;
}
private int findStudent(String student) {
for (int i = 0; i <
numberOfStudents; i++) {
if (studentsName[i].equals(student)) {
return i;
}
}
return -1;
}
}
package courseecom616;
import java.util.Scanner;
import java.util.ArrayList;
public class d {
ArrayList <Students> students = new
ArrayList<> ();
public static void
main(String[] args) {
CourseeCOM616 com616 =
new CourseeCOM616("com616");
Com616.addStudent("Danny");
com616.addStudent("Harvey");
com616.addStudent("Joseph");
com616.addStudent("Ben");
com616.addStudent("Frank");
int sum = 0;
String students1[] =
com616.getStudentsName();
sum +=
com616.getNumberOfStudents();
students1 =
com616.getStudentsName();
Scanner scan = new
Scanner(System.in);
System.out.println("Welcome to College");
int choice;
do {
System.out.println("1) View Student");
System.out.println("2) Insert Student");
System.out.println("3) Remove a student");
System.out.println("4) Delete a student by ID");
System.out.println("5) Delete a student by name");
System.out.println("6) Exit");
choice = scan.nextInt();
if (choice == 1) {
for (int i = 0; i < students1.length; i++) {
System.out.println("Index number is: " + (i) + "---> " +
students1[i]);
students1 = com210.getStudentsName();
}
System.out.println("Number of students attending the Course is: " +
sum);
} else if (choice == 2) {
System.out.println("Enter the name of student and index: ");
scan.nextLine();
String student = scan.nextLine();
int index = scan.nextInt();
students1 = com616.addStudentByIndex(student, 3);
com616.display(students1);
sum = com616.getNumberOfStudents();
System.out.println("\nThe students in the course " +
com616.getCourseName() + ":" + sum);
System.out.println("------------------------------------------");
System.out.println();
} else if (choice == 3) {
System.out.println("Remove a student by index");
int index = scan.nextInt();
students1 = com616.removeStudentByIndex(students1, index);
sum = com616.getNumberOfStudents();
System.out.println("After student drop number is: " +
sum);
System.out.println("------------------------------------");
} else if (choice == 4) {
System.out.println("Delete a students name by their ID");
System.out.println("Enter students ID: ");
String name = scan.nextLine();
String Id = scan.nextLine();
} else if (choice == 5) {
System.out.println("Delete student by name");
System.out.println("Enter student name");
String name = scan.next();
students1 = com616.deleteStudentByName(students1, name);
com616.display(students1);
sum = com616.getNumberOfStudents();
System.out.println("After the student is dropped the number will
be: " + sum);
}
}
while (choice != 6);
System.out.println("This Program has ended");
}
}
In: Computer Science
Running laps: This is C++ Programming Coding Language
Everyone likes running laps in gym class right?
There are 5 objectives and 20 points each. Please indicate in code (or comments) where each objective begins and ends. It may be prudent to place each objective in it's own function.
In this lab you will be reading in a file of student results. The students each ran 3 laps in a race and their times to complete each lap are posted in the order that they completed the lap (the students will not necessarily be in the same order each lap). You will be outputting a number of results based on the student performance. And it should go without saying that you cannot hard-code any of the values into your program as the values I’ve given as an example are not the same values I will use to test it with. There is a maximum of 20 students that may participate in the race (though the example file only has 7).
Hint: times in the files are given as minutes:seconds. But many times, you need to add or do calculations with them together. So you will need to convert them to total seconds to do these calculations. Then for displaying you will need a function for converting them back.
Objective 1: Output the final times of all the students. I also want to know who placed 1st, 2nd and 3rd overall. (Though if you have them all in order that will be sufficient). You can order values simply by setting aside 3 variables and when you calculate a new score you see if it is the best, if so move the old best into 2nd place and move the 2nd place into 3rd place. If it isn’t the best, then move down to 2nd and try that one and so on.
I should also note that you may read a file as many times as you want. Though it is not necessarily the most efficient solution you may read the file over again for each student that participated.
Objective 2: I want the averages for each lap by all the students. Then output which students are above the average and which are below:
Lap 1 average: 2:05
Below: Akano, Wes, Kye, Edward (note that Edward is right on the
border and could be put in either)
Above: Jess, Ally, Wilt
Objective 3: Naturally, the students slowed down from lap to lap as they were running. I want the lap times and the difference between them posted for each student:
Lap 1
2 3
Akano 1:48 2:28 2:25
+40 -3 (note that she is one of the few
that needs a negative)
Objective 4: Consistency in races is important. I want to know the total range of each students fastest and slowest lap. In the end I want to know the top 3 most consistent runners:
Slowest
fastest difference
Akano:
2:28
1:48 40 sec
Objective 5: Now you are going to use both the example files together. The second results file contains the same students (though my test data will be 2 files with different number and names than the files you are given). I want a comparison of the student’s overall times from each results file:
1
2 difference
Akano: 6:41 5:49
-52 sec
Lap 1: Akano 1:48 Edward 1:50 Wes 1:55 Kye 1:59 Ally 2:04 Jess 2:18 Wilt 2:44 RESULTS TXT 1 Lap 2: Edward 1:56 Kye 2:21 Jess 2:21 Akano 2:28 Ally 2:33 Wes 2:43 Wilt 3:14 Lab 3: Kye 2:11 Akano 2:25 Wilt 3:01 Ally 3:10 Jess 3:11 Wes 3:18 Edward 3:34
Lap 1: Akano 1:43 Wes 1:45 Kye 1:52 Edward 2:05 Jess 2:14 Ally 2:26 Wilt 2:30 RESULTS TXT 2 Lap 2: Edward 1:50 Akano 2:00 Wes 2:03 Kye 2:15 Jess 2:16 Ally 2:23 Wilt 2:54 Lab 3: Kye 2:01 Akano 2:06 Ally 2:54 Wes 3:03 Wilt 3:11 Jess 3:15 Edward 3:21
In: Computer Science
In C++
Make changes to List.h and List.cpp, but not City.h or City.cpp.
Project includes Cities01.txt , City.h ,City.cpp , List.h , List.cpp , and Trial.cpp
Cities01.txt
Lansing 42.73 -84.55
Detroit 42.33 -83.04
Flint 43.01 -83.68
Grand-Rapids 42.96 -85.66
Jackson 42.27 -84.47
Kalamazoo 42.23 -85.55
Ann-Arbor 42.22 -83.75
Mt-Pleasant 43.60 -84.78
Clare 43.82 -84.77
Saginaw 43.42 -83.95
City.h
// City class definition
class city
{ friend class list;
public:
city(); // Constructor
bool get(istream& in); // Input name & location
void put(ostream& out); // Output data
private:
string name; // Name
float latitude,longitude; // Location
};
List.h
#define LIST_SIZE 20
#include "City.h"
class list
{ public:
list(); // Constructor - empty list
bool insert(city arg); // Add a city
void display(ostream& out); // Output data
void sort(string arg); // Sort by distance from arg
int size(); // Return number of cities
private:
int len; // Number of used cities
city map[LIST_SIZE]; // Data set
};
City.cpp
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
#include "City.h"
/**************************************
* Constructor - no parameters
**************************************/
city::city()
{ name = "";
latitude = longitude = 0.0F;
}
/**************************************
* Get
**************************************/
bool city::get(istream &in)
{ in >> name;
in >> latitude;
in >> longitude;
return in.good();
}
/**************************************
* Put
**************************************/
void city::put(ostream &out)
{ out << left;
out << setw(14) << name;
out << right << fixed << setprecision(2);
out << setw(8) << latitude;
out << setw(8) << longitude;
}
List.cpp
#include <iostream>
#include <iomanip>
using namespace std;
#include "List.h"
/*************************************
* list()
*************************************/
list::list()
{ len = 0;
}
/*************************************
* insert()
*************************************/
bool list::insert(city arg)
{
// Check to see if there is room
if(len>=LIST_SIZE) return false;
// Add to array
map[len++] = arg;
// Return success
return true;
}
/*************************************
* display()
*************************************/
void list::display(ostream &out)
{
}
/*************************************
* size()
************************************/
int list::size()
{ return len;
}
Trial.cpp
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
#include "List.h"
/*************************************
* main()
*************************************/
void main()
{ string name;
fstream infile;
city c;
list state;
// Load from file
cout << "Enter file name: ";
cin >> name;
cout << endl;
infile.open(name,ios::in);
if(!infile.is_open()) return;
while(c.get(infile)) state.insert(c);
infile.close();
// Display
cout << state.size() << " Cities" << endl
<< endl;
state.display(cout);
/* Steps 10.6-7
// Sort by closest to here and display
cout << "Enter home city: ";
cin >> name;
cout << endl;
state.sort(name);
state.display(cout);
*/
}
Could use some help with implementing the list::display() function so the output looks like this:
Enter file name: Cities01.txt
10 Cities
City Lat Long
-------------- ------ ------
Lansing 42.73 -84.55
Detroit 42.33 -83.04
Flint 43.01 -83.68
Grand-Rapids 42.96 -85.66
Jackson 42.27 -84.47
Kalamazoo 42.23 -85.55
Ann-Arbor 42.22 -83.75
Mt-Pleasant 43.60 -84.78
Clare 43.82 -84.77
Saginaw 43.42 -83.95
Create a private function list::dist() that takes two integers src and dst, and calculates the distance between the cities at index src and dst. Hint:
Distance = Sqrt((latsrc-latdist)^2+(longsrc-longdist)^2)
Update the display() function so it calls the distance() function to display the distance between each city and the first city in the list. Uncomment the section in main() for steps 10.6-7. Implement the list::sort() function in two parts:
Output should look like this:
Enter file name: Cities01.txt
10 Cities
City Lat Long Dist
-------------- ------ ------ ------
Lansing 42.73 -84.55 0.00
Detroit 42.33 -83.04 1.56
Flint 43.01 -83.68 0.91
Grand-Rapids 42.96 -85.66 1.13
Jackson 42.27 -84.47 0.47
Kalamazoo 42.23 -85.55 1.12
Ann-Arbor 42.22 -83.75 0.95
Mt-Pleasant 43.60 -84.78 0.90
Clare 43.82 -84.77 1.11
Saginaw 43.42 -83.95 0.91
Enter home city: Lansing
City Lat Long Dist
-------------- ------ ------ ------
Lansing 42.73 -84.55 0.00
Jackson 42.27 -84.47 0.47
Mt-Pleasant 43.60 -84.78 0.90
Flint 43.01 -83.68 0.91
Saginaw 43.42 -83.95 0.91
Ann-Arbor 42.22 -83.75 0.95
Clare 43.82 -84.77 1.11
Kalamazoo 42.23 -85.55 1.12
Grand-Rapids 42.96 -85.66 1.13
Detroit 42.33 -83.04 1.56
In: Computer Science