1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Paul [167]
3 years ago
8

(a) Write a SCHEME function (make-change n den) which outputs a list of change specifications. Namely, a call (make-change 11 (l

ist 25 10 5 1) produces the list
((1 1 1 1 1 1 1 1 1 1 1) (1 1 1 1 1 1 5) (1 5 5) (1 10))
Hints: a helper function (helper n den cur) that takes as input cur, a list of coins given out so far will surely come in handy! Also, the order in which the "options" appear in the top list is immaterial.

(b) While getting the output above is helpful, it is not particularly readable. Indeed, the list (1 1 1 1 1 1 5) that states 6 pennies and 1 nickel could be far more readable as ((6 . 1) (1 . 5)) also stating 6 pennies and 1 nickel. That is, this is a list of pairs telling us how many of each denomination. Thankfully, the former can be translated into the latter by a conversion known as run length encoding that replaces sequences of an identical value by a pair giving the number of repetition of the value.
Write a SCHEME function (rle coins) which, given a list of coins, returns a list of pairs denoting the number of repetitions of each sequence of consecutive values. As a last example, the list
(list 1 1 1 1 1 1 1 5 5 5 5 1 1 1 10 10 10 1 1 25 25 25 25 25 25)
would be encoded as
( (17. 1) (4.5) (3 . 1) (3. 10) (2 . 1) (6. 25) )
Note how the tree sub-sequences of pennies are not collapsed into a single value. Those are kept as separate pairs. Naturally, this function only works for one element of the output from make-change.
Computers and Technology
1 answer:
pentagon [3]3 years ago
7 0

Answer:

#include <iostream>

using namespace std;

// Function to find the total number of ways to get change of N

// from unlimited supply of coins in set S

int count(int S[], int n, int N)

{

// if total is 0, return 1

if (N == 0)

 return 1;

// return 0 if total become negative

if (N < 0)

 return 0;

// initialize total number of ways to 0

int res = 0;

// do for each coin

for (int i = 0; i < n; i++)

{

 // recur to see if total can be reached by including

 // current coin S[i]

 res += count(S, n, N - S[i]);

}

// return total number of ways

return res;

}

// Coin Change Problem

int main()

{

// n coins of given denominations

int S[] = { 1, 2, 3 };

int n = sizeof(S) / sizeof(S[0]);

// Total Change required

int N = 4;

cout << "Total number of ways to get desired change is "

  << count(S, n, N);

return 0;

}

You might be interested in
Como puedo poner fondo a mi teclado​
nikdorinn [45]

CAN YOU TRANSLATE IT TO ENGLISH PLEASE SO I CAN AWANSER

7 0
3 years ago
Write a Java program that generates GUI (Graphical User Interface). Your program should provide labels and textfields to a user
Alla [95]

Answer:

import javafx.application.Application;

import javafx.stage.Stage;

import javafx.scene.Scene;

import javafx.scene.control.Tab;

import javafx.scene.control.TabPane;

import javafx.scene.layout.StackPane;

import java.util.ArrayList;

public class Assignment6 extends Application {

private TabPane tabPane;

private CreatePane createPane;

private SelectPane selectPane;

private ArrayList<Club> clubList;

public void start(Stage stage) {

StackPane root = new StackPane();

//clubList to be used in both createPane & selectPane

clubList = new ArrayList<Club>();

selectPane = new SelectPane(clubList);

createPane = new CreatePane(clubList, selectPane);

tabPane = new TabPane();

Tab tab1 = new Tab();

tab1.setText("Club Creation");

tab1.setContent(createPane);

Tab tab2 = new Tab();

tab2.setText("Club Selection");

tab2.setContent(selectPane);

tabPane.getSelectionModel().select(0);

tabPane.getTabs().addAll(tab1, tab2);

root.getChildren().add(tabPane);

Scene scene = new Scene(root, 900, 400);

stage.setTitle("Club Selection Apps");

stage.setScene(scene);

stage.show();

}

public static void main(String[] args)

{

launch(args);

}

}

import java.util.ArrayList;

import javafx.scene.layout.HBox;

import javafx.event.ActionEvent; //**Need to import

import javafx.event.EventHandler; //**Need to import

public class CreatePane extends HBox {

ArrayList<Club> clubList;

private SelectPane selectPane;

//constructor

public CreatePane(ArrayList<Club> list, SelectPane sePane) {

this.clubList = list;

this.selectPane = sePane;

}

//using the toString method of the Club class.

//It also does error checking in case any of the textfields are empty,

//or a non-numeric value was entered for its number of members

private class ButtonHandler implements EventHandler<ActionEvent> {

//Override the abstact method handle()

public void handle(ActionEvent event) {

//declare any necessary local variables here

//---

//when a text field is empty and the button is pushed

//if ( //---- )

//{

//handle the case here

//}

//else //for all other cases

//{

//when a non-numeric value was entered for its number of

members

//and the button is pushed

//you will need to use try & catch block to catch

//the NumberFormatException

//When a club of an existing club name in the list

//was attempted to be added, do not add it to the list

//and display a message "Club not added - duplicate"

//at the end, don't forget to update the new arrayList

//information on the SelectPanel

//}

} //end of handle() method

} //end of ButtonHandler class

}

import javafx.scene.control.Label;

import javafx.scene.control.CheckBox;

import javafx.scene.layout.*;

import javafx.event.ActionEvent; //**Need to import

import javafx.event.EventHandler; //**Need to import

import java.util.ArrayList;

import javafx.collections.ObservableList;

import javafx.scene.Node;

//import all other necessary javafx classes here

public class SelectPane extends BorderPane {

private ArrayList<Club> clubList;

//constructor

public SelectPane(ArrayList<Club> list) {

//initialize instance variables

this.clubList = list;

//set up the layout

//create an empty pane where you can add check boxes later

//SelectPane is a BorderPane - add the components here

} //end of constructor

//This method uses the newly added parameter Club object

//to create a CheckBox and add it to a pane created in the constructor

//Such check box needs to be linked to its handler class

public void updateClubList(Club newClub)

{

//-------

}

//create a SelectionHandler class

private class SelectionHandler implements EventHandler<ActionEvent> {

//Override the abstact method handle()

public void handle(ActionEvent event){

//When any radio button is selected or unselected

//the total number of members of selected clubs should be updated

//and displayed using a label.

}

} //end of SelectHandler class

} //end of SelectPane class

public class Club {

private String clubName;

private int numberOfMembers;

private String university;

//Constructor to initialize all member variables

public Club() {

clubName = "?";

university = "?";

numberOfMembers = 0;

}

//Accessor method for club name

public String getClubName() {

return clubName;

}

//Accessor method for university

public String getUniversity() {

return university;

}

//Accessor method for number of members

public int getNumberOfMembers() {

return numberOfMembers;

}

//mutator/modifider method for club name

public void setClubName(String someClubName) {

clubName = someClubName;

}

//mutator/modifider method for university

public void setUniversity(String someUniversity) {

university = someUniversity;

}

//mutator/modifider method for number of members

public void setNumberOfMembers(int someNumber) {

numberOfMembers = someNumber;

}

//toString() method returns a string containg its name, number of members, and

university

public String toString() {

String result = "\nClub Name:\t\t" + clubName

+ "\nNumber Of Members:\t" + numberOfMembers

+ "\nUniversity:\t\t" + university

+ "\n\n";

return result;

}

}

Explanation:

4 0
4 years ago
What is a graphical representation of a real person in a virtual community called?
Hitman42 [59]
A graphical representation of a real person in a virtual community is an avatar.
8 0
3 years ago
With a ____, the databases used by the system are all located on a single computer, such as a server or mainframe computer.
denpristay [2]

With a centralized database system, the databases used by the system are all located on a single computer, such as a server or mainframe computer.

<h3></h3><h3>What are database systems?</h3>

Database is a collection of related data stored in a manner that it can be retrieved as needed. Database system or Database Management System (DBMS) are enables us to create, maintain, and access databases. A database typically consists of Tables, Fields (columns) and Records (rows).

Advantages of DBMS approach are low level of redundancy, faster response time, lower storage requirements, easier to secure, increased data accuracy. Disadvantage of DBMS approach is increased vulnerability (backup is essential).

To learn more about database systems refer to:

brainly.com/question/518894

#SPJ4

5 0
2 years ago
16. The data selected to create a chart must include
Murljashka [212]

Answer:

B.column titles and row labels

8 0
3 years ago
Other questions:
  • An email address is made up of all of the following parts except
    13·2 answers
  • A formula =A1+B2 is in cell D8. If you copy that formula to cell D9, what is the new formula in cell D9? A. '=A1+B2 B. '=A2+B3 C
    8·2 answers
  • What is the real meaning of hack and crack?
    6·1 answer
  • In 3-4 sentences, write a note to a friend describ
    6·2 answers
  • Create a new program called Time.java. From now on, we won’t remind you to start with a small, working program, but you should.
    13·1 answer
  • _____ are independent and not associated with the marketing efforts of any particular company or brand.​
    9·1 answer
  • Which statement best compares routers and hubs?
    9·1 answer
  • Explain the following as used in Tally Accounting Software:
    8·1 answer
  • C++ "Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the se
    12·1 answer
  • Vhat is the result when you run the following program?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!