Questions
4.4 Lab: Arrays of Pointers to Structures (Sort) C++ programming This assignment is based on Homework...

4.4 Lab: Arrays of Pointers to Structures (Sort)

C++ programming

This assignment is based on Homework 3. The program will create an array of Airport structures. On the first line in the input file airports.txt there is an integer n, representing the number of lines in the input file. On each of the following n lines there is an airport code (a unique identifier) followed by the airport’s number of enplanements (commercial passenger boardings), and city served. You may assume that the data in the input file are sorted by the airport’s code as shown below:

4
BFL 100433 Bakersfield 
BUR 2077892 Burbank
LAX 39636042 Los Angeles 
MRY 192136 Monterey

Read n from this input file and use it to dynamically allocate an array of structures. Then continue reading from file to put data into the dynamically allocated array.

Create an array of n pointers to Airport structures and initialize each pointer to point to the corresponding element in the array of Airport structures.

Change the insertion sort algorithm to rearrange the pointes in the array of pointers to show the array of structures in descending order by the airport’s number of enplanements.

When done sorting the pointers, display the following report:

Original Order                   Descending (enp)
BFL Bakersfield        100433    LAX Los Angeles      39636042
BUR Burbank           2077892    BUR Burbank           2077892
LAX Los Angeles      39636042    MRY Monterey           192136
MRY Monterey           192136    BFL Bakersfield        100433

/*~*~*~*~*~*~
Pointers, Arrays, Structures, Sorting, and Dynamic Allocation of Memory
Name:
IDE:
*/

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

struct Airport
{
string code;
string city;
int enp;
};

// function prototypes
Airport *readArpData(string filename, int &size);
Airport **createPtrArray(Airport *list, int size);
void insertSort(Airport **pArp, int size);
void displayReport(Airport **pArp, Airport *list, int size);

int main()
{
Airport *list; // pointer to work with a dynamically allocated array of structs
Airport **pArp; // pointer to work with an array of pointers to structs
int size;
string filename = "airports.txt";
  
// function calls
cout << "Enter input file name: ";
cin >> filename;
// call readArpData
// call createPtrArray
// call insertSort
// call displayReport
  
return 0;
}

/*~*~*~*~*~*~
This function does the following:
- opens the input file(with validation: exit if file not found)
- reads size from the input file (the first number)
- dynamically allocates an array of size Airport structures
- reads data for size airports into the dynamically allocated array
- closes the input file
- returns the pointer to the dynamically allocated array
*~*/
Airport *readArpData(string filename, int &size)
{
ifstream inputFile;
Airport *list;
  
/* Write your code here */
  
return list;
}

/*~*~*~*~*~*~
This function ...

*~*/
Airport **createPtrArray(Airport *list, int size)
{
Airport **pArp;
  
/* Write your code here */
  
return pArp;
}

/*~*~*~*~*~*~
This function ...

*~*/
void insertSort(Airport **list, int size)
{
/* Write your code here */
}

/*~*~*~*~*~*~
This function ...

*~*/
void displayReport(Airport **pArp, Airport *list, int size)
{
cout << "\nOriginal Data Descending (enp)" << endl;
for (int i = 0; i < size; i++){
cout << /* code */ << " "
<< setw(15) << left << /* city */
<< setw(10) << right << /* enp */ << " ";
cout << /* code */ << " "
<< setw(15) << left << /* city */
<< setw(10) << right << /* enp */ << endl;
}
}


/*~*~*~*~*~*~ Save the output below

*~*/


In: Computer Science

Question 3 A. Show the output of the following code. #include <iostream> using namespace std; void...

Question 3

A. Show the output of the following code.

#include <iostream>

using namespace std;

void magic (int &a, int b, int& c)

{

  a *= 2;

   b = b+2;

   c = c-2;

}

int main ()

{

int x=1, y=3, z=7;

   magic (x, y, z);

cout << "x=" << x << ", y=" << y << ", z=" << z;

   magic (z, y, x);

cout << "x=" << x << ", y=" << y << ", z=" << z;

   return 0;

}

What is the parameter passing scheme for a, b and c in magic( ) function ?

B. Show the output of the following code.

#include <iostream>

using namespace std;

void printarray (int arg[], int length) {

   for (int n=length-1; n>=0; n--)

cout << arg[n] << " ";

   cout << endl;

}

int main ()

{

int firstarray[] = {3, 15, 10};

   int secondarray[] = {2, 4, 6, 8, 10};

   printarray (firstarray,2);

   printarray (secondarray,3);

   return 0;

}

In: Computer Science

Python Knapsack Problem: Acme Super Store is having a contest to give away shopping sprees to...

Python Knapsack Problem:

Acme Super Store is having a contest to give away shopping sprees to lucky families. If a family wins a shopping spree each person in the family can take any items in the store that he or she can carry out, however each person can only take one of each type of item. For example, one family member can take one television, one watch and one toaster, while another family member can take one television, one camera and one pair of shoes.

Each item has a price (in dollars) and a weight (in pounds) and each person in the family has a limit in the total weight they can carry. Two people cannot work together to carry an item. Your job is to help the families select items for each person to carry to maximize the total price of all items the family takes. Write an algorithm to determine the maximum total price of items for each family and the items that each family member should select.

***In python:***

Implement your algorithm by writing a program named “shopping.py”. The program should satisfy the specifications below.

Input: The input file named “shopping.txt” consists of T test cases

T (1 ≤ T ≤ 100) is given on the first line of the input file.

Each test case begins with a line containing a single integer number N that indicates the number of items (1 ≤ N ≤ 100) in that test case

Followed by N lines, each containing two integers: P and W. The first integer (1 ≤ P ≤ 5000) corresponds to the price of object and the second integer (1 ≤ W ≤ 100) corresponds to the weight of object.

The next line contains one integer (1 ≤ F ≤ 30) which is the number of people in that family.

The next F lines contains the maximum weight (1 ≤ M ≤ 200) that can be carried by the ith person in the family (1 ≤ i ≤ F).

Output: Written to a file named “results.txt”. For each test case your program should output the maximum total price of all goods that the family can carry out during their shopping spree and for each the family member, numbered 1 ≤ i ≤ F, list the item numbers 1 ≤ N ≤ 100 that they should select.

Sample Input:

2

3

72 17

44 23

31 24

1

26

6

64 26

85 22

52 4

99 18

39 13

54 9

4

23

20

20

36

Sample Output:

Test Case 1

Total Price 72

Member Items

1: 1

In: Computer Science

In java What program would you write to solve the following problems and why does it...

In java What program would you write to solve the following problems and why does it work? Please also comment on other students’ code at least three times. 1) Write code to partition a linked list around a value x, such that all nodes less than x come before all nodes greater than or equal to x. If x is contained within the list, the values of x only need to be after the elements less than x. The partition element x can appear anywhere in the “right partition”; it does not need to appear between the left and right partitions. Input: 3à5à8à5à10à2à1 (partition=5) Output: 3à1à2à10à5à5à8. 2) Write a method that finds the maximum of two numbers. You should not use if-else or any other comparison operator. 3) Write methods to implement the multiply, subtract and divide operations for integers. The results of all of these are integers. Use only the add operator.

In: Computer Science

Visual Basics In this exercise, you modify the History Grade application from this chapter’s Focus lesson....

Visual Basics

In this exercise, you modify the History Grade application from this chapter’s Focus lesson. Use Windows to make a copy of the History Solution folder. Rename the copy History Solution-Functions. Open the History Solution.sln file contained in the History Solution-Functions folder. Modify the btnDisplay_Click procedure so that it uses two functions named GetGrade101 and GetGrade201 to get the appropriate grade; the procedure should then display the grade in the lblGrade control. Change the two independent Sub procedures to functions that return the appropriate grade to the statements that invoke them in the btnDisplay_Click procedure. Each function should contain a parameter that accepts the total points passed to it. Save the solution and then start and test the application.

Option Explicit On
Option Strict On
Option Infer Off

Public Class frmMain
    ' Independent Sub procedures.


    Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
        ' Calls independent Sub procedures to display a grade.


    End Sub

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub txtPoints_Enter(sender As Object, e As EventArgs) Handles txtPoints.Enter
        txtPoints.SelectAll()
    End Sub

    Private Sub ClearGrade(sender As Object, e As EventArgs) Handles txtPoints.TextChanged, radHis101.CheckedChanged, radHis201.CheckedChanged
        lblGrade.Text = String.Empty
    End Sub

    Private Sub txtPoints_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtPoints.KeyPress
        ' Accept only numbers and the Backspace key

        If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then
            e.Handled = True
        End If
    End Sub

In: Computer Science

Both in Java Question 1: Write a method, bunnyEars that takes in a integer for a...

Both in Java
Question 1:
Write a method, bunnyEars that takes in a integer for a number of bunnies and return another integer for the total number of ears that the group of bunnies has. (Assume ear bunny has exactly 2 ears)..
Write a method countX, that when given a string counts the number of lowercase 'x' chars in the string.
countX("xxhixx") → 4
countX("xhixhix") → 3
countX("hi") → 0

Write a method copies that, when given a string and a non-empty substring sub, compute recursively if at least n copies of sub appear in the string somewhere, possibly with overlapping. N will be non-negative.
strCopies("catcowcat", "cat", 2) → true
strCopies("catcowcat", "cow", 2) → false
strCopies("catcowcat", "cow", 1) → true


Question 2:

Shape Interface
Create an interface called Shape.java
Give it two methods: area, perimeter. Each should return a double.
Rectangle
Create a concrete class Rectangle that implements Shape.
Give it a height, width, and a constructor that sets both of them.
The area of a rectangle is height X width
The perimeter of a rectangle is 2 * height + 2 * width
Square
Create a concrete class Square that implements Shape.
Give it a width, and a constructor that sets it.
The area of a square is width X width
The perimeter of a circle is width + width + width + width
Triangle
Create a concrete class triangle that implements Shape.
Give it a length for 3 sides and a constructor that sets them
The area of a triangle is 1/2 base * height
The perimeter of a triangle the sum of its sides
Equilateral Triangle
Create a concrete class EquilateralTriangle that implements Shape.
Give it a length for 1 sides and a constructor that sets all of its sides to it.
The area of a triangle is 1/2 base * height
The perimeter of a triangle the sum of its sides
Circle
Create a concrete class Circle that implements Shape.
Give it a value radius and a constructor that sets it.
The area of a circle is 2 * pi * radius
The perimeter of a circle is pi * radius * radius

In: Computer Science

Please write a C++ code that inputs a CSV file, asks the user if they'd like...

Please write a C++ code that inputs a CSV file, asks the user if they'd like to remove certain words from the file, and removes the words from the file.

Please note that the CSV file has two columns, the first with the words, and the second with a count of how many times each word appears.

In: Computer Science

Discuss why alternative IS development approaches have evolved, and provide an overview of a couple of...

Discuss why alternative IS development approaches have evolved, and provide an overview of a couple of these methodologies.

In: Computer Science

First, review the following Context DFD examples Medical Chart Tracking System Grading System Order System Correct...

First, review the following Context DFD examples

  • Medical Chart Tracking System
  • Grading System
  • Order System
  • Correct and Incorrect Examples of Data Flows

Second, create a Context DFD (using Lucidchart or other software) of a process of your choice. Your Context DFD should include at least 3 external entities and at least 6 data flows.

Save your Context DFD as an image file or link and insert it into your post.

Type a few sentences explaining your system.

Name the internal processes, data stores, and additional data flows that would be included in a Diagram 0 for your process. (You do not need to create the Diagram 0 - you only need to name the additional internal processes, data stores, and data flows).

In: Computer Science

Print the message “ I start to learn a C – Program “ on two lines...

  1. Print the message “ I start to learn a C – Program “ on two lines where the first line ends with “learn”.
  2. Write a full C program to output following printf statement.

Printf (“ This \nis\na\nC\nprogram. \n”);

  1. Write a C program to output following printf statement.

Printf(“\n This is \ a \n C program. “) ;

  1. Write a program that prints the numbers 1 to 4 on same lines after one blank line.
  2. Write a program to display following block letters.

C   C   C C   C

      C

           C

                C

  1. Calculate mean of given 3 numbers: 45, 55, 65.(Division operator is /).
  2. Using if, evaluate whether a number entered by the keyboard is greater or less than 10.

In: Computer Science

HTML/CSS/JavaScript Create a page that converts 4 different measurements (i.e. length, volume, area, distance) to either...

HTML/CSS/JavaScript

Create a page that converts 4 different measurements (i.e. length, volume, area, distance) to either Imperial or Metric values. When a value is entered into one of the fields, the converted amount is displayed in the other corresponding field.

Example:

Converting between litres and gallons. If you enter 25 for gallons, the value of 113.50 litres should be displayed.

Converting between gallons and litres. If you enter 75 litres, the value of 16.52 gallons should be displayed. (Note, 1 Imperial gallon is 4.54 litres)

Example:

Converting between metres and feet. If you enter 125 for feet, the value of 38.10 metres should be displayed.

Example:

Converting square metres to feet. If you enter 95 for square metres, the value of 1022.57 square feet should be displayed.

Your page will require JavaScript ‘event handlers’ that will respond to changes in the number field and call the correct functions. Your answers should display to 2 significant digits. Your page must use CSS to create an interesting and pleasing interface

In: Computer Science

2- Plain Text (Message): a) JERSEY b) CALIFORNIA Key: CSEC Scheme: Vigenere Cipher Cipher Text:

2- Plain Text (Message):

a) JERSEY

b) CALIFORNIA

Key: CSEC

Scheme: Vigenere Cipher

Cipher Text:

In: Computer Science

A Deque is an ADT which allows efficient (O(1)) insertion and removal at either end of...

A Deque is an ADT which allows efficient (O(1)) insertion and removal at either end of the structure. Typically, a deque is implemented with a doubly-linked list (DLL), and has the following API:

addFront(data)  # adds element to head of the DLL
removeFront()   # removes (and returns) element from head of the DLL
addRear(data)   # adds element to the tail of the DLL
removeRear()    # removes (and returns) element from the tail of the DLL

Which of the Deque operations could be used to implement the Queue ADT enqueue and dequeue methods, respectively:

A deque cannot be used to implement a queue


addFront, removeFront


addFront, removeRear


addRear, removeFront


(addFront, removeRear) or (addRear, removeFront)


addRear, removeRear


(addFront, removeFront) or (addRear, removeRear)

In: Computer Science

Discuss the security features in SNMPV3 that SNMPV1 and SNMPV2 do not provide

Discuss the security features in SNMPV3 that SNMPV1 and SNMPV2 do not provide

In: Computer Science

SQL Trigger problem When attemptiing to Create or Replace a trigger I get the error "sql...

SQL Trigger problem

When attemptiing to Create or Replace a trigger I get the error "sql warning trigger created with compilation errors".

Trigger:

CREATE OR REPLACE TRIGGER Late_Fees
after UPDATE
ON InventoryItem
FOR EACH ROW

DECLARE

late_fee number;
num_days number;
BEGIN
num_days:= to_date(:old.ReturnDate)-TO_DATE(:old.DateDue);
select IntValue into late_fee from ApplicationSettings where Setting='Daily Late Fee';
:new.fee := (late_fee)*(num_days);

END;
/

commit;

Table:

create table Rental(
INVID int Primary key,
LoanDate date,
PatronID int,
DueDate date,
ReturnDate date,
constraint PatronID_FK Foreign key (PatronID) references Patrons(PatronID));

Test Input:

insert into rental
values ('1345', '2020-02-20', '000', '2020-02-27', '2020-02-22');
insert into rental
values ('1345', '2020-04-10', '000', '2020-04-17', '2020-04-17');
insert into rental
values ('1234', '2020-02-20', '000', '2020-02-27', '2020-02-22');
insert into rental
values ('1245', '2020-02-20', '000', '2020-02-27', '2020-02-22');
insert into rental
values ('1345', '2020-08-14', '0001', '2020-08-21', '2020-08-20');
insert into rental
values ('1265', '2020-09-01', '0001', '2020-09-08', '2020-09-10');

In: Computer Science