Cant figure out why my out is wrong for my c++ program.
for example if the initial value is 100, the intrest rate is 10%, and it takes 6 months for maturity the output should be $105 but instead it outputs 101.657 please help.
#include <iostream>
#include <cmath>
using namespace std;
struct account
{
double balance;
double interest_rate;
int term;
};
void info(account& accountinfo);
int main(void)
{
double calc1, calc2, calc3;
account accountinfo;
info(accountinfo);
calc1 = accountinfo.interest_rate / 100;
calc2 = accountinfo.term / 12;
calc3 = (accountinfo.balance * pow (1 + calc1 / 365, 365 / accountinfo.term));
cout << " " << endl
<< " The balance of your CD account after it has matured in " << accountinfo.term << " months " << endl
<< " at a interest rate of " << accountinfo.interest_rate << " percent will be " << calc3 << endl
<< " " << endl;
return 0;
}
void info(account& accountinfo)
{
cout << " " << endl
<< " This program calculates the value of a CD after maturity. " << endl
<< " " << endl
<< " Enter the balance on the account. " << endl;
cin >> accountinfo.balance;
cout << " " << endl
<< " Enter the interest rate for the CD. " << endl
<< " " << endl;
cin >> accountinfo.interest_rate;
cout << " " << endl
<< " Enter the term for the CD to achieve maturity (in months). " << endl
<< " " << endl;
cin >> accountinfo.term;
}
In: Computer Science
q7.1 Fix the errors in the code (in C)
//This program should read a string from the user and print it using a character pointer
//The program is setup to use pointer offset notation to get each character of the string
#include <stdio.h>
#include <string.h>
int main(void){
char s[1];
scanf(" %c", s);
char *cPtr = s[1];
int i=0;
while(1){
printf("%c", cPtr+i);
i++;
}
printf("\n");
}
In: Computer Science
. Create a batch file (hw3_yourlastname1.bat) which will schedule tasks on the system using Windows 10’s Scheduled Task Console utility - schtasks
Your batch file (hw3_yourlastname1.bat) will include instructions to do the followings:
a. List the directories and files in the current directory
b. Pause the script to see the list of directories and files
c. Clear the screen
d. Pause the script
e. Schedule a task to start Check Disk (chkdsk.exe) every Friday at 5:30pm using Scheduled Task Console (schtasks) utility
f. Schedule a task to start Disk Defragmenter (dfrgui.exe) every 1st day of a month at 11:30pm using Scheduled Task Console (schtasks) utility
g. Display all the scheduled tasks on the system
h. Pause the script to see the list of scheduled tasks
In: Computer Science
home / study / engineering / computer science / questions and answers / working with layout managers. notes: 1. in part ... Your question has been answered Let us know if you got a helpful answer. Rate this answer Question: Working with Layout Managers. Notes: 1. In part 2,... Bookmark Working with Layout Managers. Notes: 1. In part 2, note that the Game class inherits from JPanel. Therefore, the panel you are asked to add to the center of the content pane is the "game" object. 2. In part 4, at the end of the function, call validate(). This is not mentioned in the book, but it is mentioned in the framework comments. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Game extends JPanel { private JButton [][] squares; private TilePuzzle game; public Game( int newSide ) { game = new TilePuzzle( newSide ); setUpGameGUI( ); } public void setUpGame( int newSide ) { game.setUpGame( newSide ); setUpGameGUI( ); } public void setUpGameGUI( ) { removeAll( ); // remove all components setLayout( new GridLayout( game.getSide( ), game.getSide( ) ) ); squares = new JButton[game.getSide( )][game.getSide( )]; ButtonHandler bh = new ButtonHandler( ); // for each button: generate button label, // instantiate button, add to container, // and register listener for ( int i = 0; i < game.getSide( ); i++ ) { for ( int j = 0; j < game.getSide( ); j++ ) { squares[i][j] = new JButton( game.getTiles( )[i][j] ); add( squares[i][j] ); squares[i][j].addActionListener( bh ); } } setSize( 300, 300 ); setVisible( true ); } private void update( int row, int col ) { for ( int i = 0; i < game.getSide( ); i++ ) { for ( int j = 0; j < game.getSide( ); j++ ) { squares[i][j].setText( game.getTiles( )[i][j] ); } } if ( game.won( ) ) { JOptionPane.showMessageDialog( Game.this, "Congratulations! You won!\nSetting up new game" ); // int sideOfPuzzle = 3 + (int) ( 4 * Math.random( ) ); // setUpGameGUI( ); } } private class ButtonHandler implements ActionListener { public void actionPerformed( ActionEvent ae ) { for( int i = 0; i < game.getSide( ); i++ ) { for( int j = 0; j < game.getSide( ); j++ ) { if ( ae.getSource( ) == squares[i][j] ) { if ( game.tryToPlay( i, j ) ) update( i, j ); return; } // end if } // end inner for loop } // outer for loop } // end actionPerformed method } // end ButtonHandler class } // end Game class import javax.swing.*; import java.awt.*; import java.awt.event.*; public class NestedLayoutPractice extends JFrame { private Container contents; private Game game; private BorderLayout bl; private JLabel bottom; // ***** Task 1: declare a JPanel named top // also declare three JButton instance variables // that will be added to the JPanel top // these buttons will determine the grid size of the game: // 3-by-3, 4-by-4, or 5-by-5 // Part 1 student code starts here: // Part 1 student code ends here. public NestedLayoutPractice() { super("Practicing layout managers"); contents = getContentPane(); // ***** Task 2: // instantiate the BorderLayout manager bl // Part 2 student code starts here: // set the layout manager of the content pane contents to bl: game = new Game(3); // instantiating the GamePanel object // add panel (game) to the center of the content pane // Part 2 student code ends here. bottom = new JLabel("Have fun playing this Tile Puzzle game", SwingConstants.CENTER); // ***** Task 3: // instantiate the JPanel component named top // Part 3 student code starts here: // set the layout of top to a 1-by-3 grid // instantiate the JButtons that determine the grid size // add the buttons to JPanel top // add JPanel top to the content pane as its north component // Part 3 student code ends here. // ***** Task 5: // Note: search for and complete Task 4 before performing this task // Part 5 student code starts here: // declare and instantiate an ActionListener // register the listener on the 3 buttons // that you declared in Task 1 // Part 5 student code ends here. contents.add(bottom, BorderLayout.SOUTH); setSize(325, 325); setVisible(true); } // ***** Task 4: // create a private inner class that implements ActionListener // your method should identify which of the 3 buttons // was the source of the event // depending on which button was pressed, // call the setUpGame method of the Game class // with arguments 3, 4, or 5 // the API of that method is: // public void setUpGame(int nSides) // At the end of the method call validate() // Part 4 student code starts here: // Part 4 student code ends here. public static void main(String[] args) { NestedLayoutPractice nl = new NestedLayoutPractice(); nl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } public class TilePuzzle { private int side; // grid size for game 1 private String[][] tiles; private int emptyRow; private int emptyCol; public TilePuzzle( int newSide ) { setUpGame( newSide ); } public void setUpGame( int newSide ) { if ( side > 0 ) side = newSide; else side = 3; side = newSide; tiles = new String[side][side]; emptyRow = side - 1; emptyCol = side - 1; for ( int i = 0; i < side; i++ ) { for ( int j = 0; j < side; j++ ) { tiles[i][j] = String.valueOf( ( side * side ) - ( side * i + j + 1 ) ); } } // set empty tile to blank tiles[side - 1][side - 1] = ""; } public int getSide( ) { return side; } /* public int getEmptyRow( ) { return emptyRow; } public int getEmptyCol( ) { return emptyCol; } */ public String[][] getTiles( ) { return tiles; } public boolean tryToPlay( int row, int col ) { if ( possibleToPlay( row, col ) ) { // play: switch empty String and tile label at row, col tiles[emptyRow][emptyCol] = tiles[row][col]; tiles[row][col] = ""; emptyRow = row; emptyCol = col; return true; } else return false; } public boolean possibleToPlay( int row, int col ) { if ( ( col == emptyCol && Math.abs( row - emptyRow ) == 1 ) || ( row == emptyRow && Math.abs( col - emptyCol ) == 1 ) ) return true; else return false; } public boolean won( ) { for ( int i = 0; i < side ; i++ ) { for ( int j = 0; j < side; j++ ) { if ( !( tiles[i][j].equals( String.valueOf( i * side + j + 1 ) ) ) && ( i != side - 1 || j != side - 1 ) ) return false; } } return true; } } Programming Activity 12-2 Guidance ================================== Overview -------- There are 5 parts. Make sure you complete the parts in numerical order. Notice that part 4 occurs in the code after part 5. As stated in the part 5 comments, you should complete part 4 before part 5 because part 5 has a step that says: "// declare and instantiate an ActionListener" This ActionListener must be an object of the private inner button handler class that you write in part 4. The 5 parts of 12-2 each have helpful comments. The comments will guide you about what code to write. Button instantiation -------------------- Suppose you define a button as follows: JButton three; To instantiate it with its label set to "3 x 3", you would write: three = new JButton("3 x 3"); Part 2 ------ Note that the Game class inherits from JPanel. Therefore, the panel you are asked to add to the center of the content pane is the "game" object. Part 4 button handler --------------------- You have to create a private inner class to handle events from any of the three game setup buttons. This course is cumulative. Each new chapter builds on previous chapters. Week 4 had a video called Java GUI Button Components. The code for that video was supplied in a folder in week 4. Here is a section of the code shown in that video: private class CommandHandler implements ActionListener { public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == btnDisplayTrees) { displayTrees(); return; } if (source == btnDisplayWater) { displayWater(); return; } if (source == btnPackWindow) { packWindow(); return; } if (source == btnReset) { reset(); return; } } etc. The above code shows a private inner class named CommandHandler that handles button events. You can name your button handler whatever you want, such as ButtonHandler, but you must use the same name in part 5 after the comment: // declare and instantiate an ActionListener In the above video example, there is an if test for each button event. Each of the if blocks does something and then returns. In your button handler, you also have to do a certain thing for each button as specified in the comments. However, you cannot then simply return because validate() must be called at the end of the function--no matter which button was clicked. There are 2 simple ways to achieve this: 1) Use nested if/else's followed by the validate() call, or 2) Call validate() after each button's processing and then return from each one as in the video example. Part 4 setUpGame() ------------------ The part 4 comments include: // depending on which button was pressed, // call the setUpGame method of the Game class // with arguments 3, 4, or 5 // the API of that method is: // public void setUpGame(int nSides) To call a function we need an object of its class. Does our framework code have an object for us of type Game? Looking near the beginning of the NestedLayoutPractice class that we are in, you will see the following declaration: private Game game; So, game is an object reference of type Game that we can use. Your framework starting code already includes the following line of code in part 2: game = new Game(3); // instantiating the GamePanel object This is where the game object is actually created. It is passed a value of 3 in the constructor call. This will cause the game to be created with 3 rows by 3 columns of numbered squares. Now back to your part 4 handler comments. The comments say to change the game setup as instructed based on which button was clicked. If you look at the example user interface you will see that there are 3 buttons to change the game to 3 x 3, or 4 x 4, or 5 x 5 squares. You should have already declared these buttons in part 1 and created them in part 3 as instructed. In part 4, your event handler function must handle when each of the buttons is clicked. If, for exaample, the 4 x 4 button is clicked, then you should have the following line of code for that event: game.setUpGame(4); Don't overthink this. It is a simple function call using the game object, its setUpGame() method, and a literal parameter of 4. At the end of the function, call
In: Computer Science
i need the pseudocode and python program for the following problem.
Besides the user entering the number of books purchased this order, they are asked for the number of
points earned for the year before this order and the number of books ordered this year before this order.
There are bonus points awarded based on the number of books previously ordered and number ordered
now. These points should be added to the variable points:
Current order: 0 Previous Orders > 10 Add 1 to point total
Current order: 1, 2, or 3 Previous Orders > 10 Add 2 to point total
Current order: > 3 Previous Orders > 10 Add 5 to point total
// main module
Module main()
// Local variables
Declare Integer points
Declare Integer yearlyBooks
Declare Integer books
// Get numbers
Call getYearlyPoints(points)
Call getYearlyBooks(yearlyBooks)
Call getBooksPurchased(books)
// Display points earned
If books == 0
Display "0 points earned this order"
// Bonus check here
Display “Total points for the year”, points
Else If books == 1
Display "5 points earned this order"
Set points = points + 5
// Bonus check here
Display “Total points for the year”, points
Else If books == 2
Display "15 points earned this order"
Set points = points + 15
// Bonus check here
Display “Total points for the year”, points
Else If books == 3
Display "30 points earned this order"
Set points = points + 30
// Bonus check here
Display “Total points for the year”, points
Else
Display "60 points earned this order"
Set points = points + 60
// Bonus check here
Display “Total points for the year”, points
End If
End Module
// The getYearlyPoints module gets number of books purchased
// this year before this month
// and stores it in the number reference variable.
Module getYearlyPoints (Integer Ref number)
Display "How many points have you earned so far this year?"
Input number
End Module
// The getYearlyBooks module gets number of books purchased
// this year before this month
// and stores it in the number reference variable.
Module getYearlyBooks (Integer Ref number)
Display "How many books did you buy this year before this month?"
Input number
End Module
// The getBooksPurchased module gets number of books purchased
// this month
// and stores it in the number reference variable.
Module getBooksPurchased (Integer Ref number)
Display "How many books did you buy this month?"
Input number
End Module
NOTE: Using the variable name number in all three modules is perfectly legal
because they are each “local” to the module. In the first module the value of
number is returned to the variable points. In the second module it is returned to
the variable yearlyBooks. In the third it is returned to books.
In: Computer Science
q7.4 Fix the errors in the code (in C)
//This program is supposed to scan 5 ints from the user
//Using those 5 ints, it should construct a linked list of 5 elements
//Then it prints the elements of the list using the PrintList function
#include <stdio.h>
struct Node{
int data;
Node* next;
};
int main(void){
struct Node first = {0, 0};
struct Node* second = {0, 0};
Node third = {0, 0};
struct Node fourth = {0, 0};
struct Node fifth = {0, &first};
int i;
scanf(" %d", &i);
first.data = i;
scanf(" %d", &i);
second.data = i
first.next = &second;
scanf(" %d", &i);
third.data = i;
second.next = third;
scanf(" %d", &i);
data = i;
third.next = &fourth;
scanf(" %d", &i);
fifth.data = i;
fourth->next = &fifth;
PrintList(first);
}
PrintList(struct Node* n){
while(n != 0){
printf("%d ", n.data);
n = n.next;
}
printf("\n");
}
In: Computer Science
There are many different security certifications that are available for the IT user. Which security certification do you think is the most important to take first, and why? Would you rather take a course or do self-study to prepare for the certification exam? Explain your answer.
In: Computer Science
Java - Create a program that simulates a slot machine. When the program runs, it should do the following: - Ask the user to enter the amount of money he or she wants to enter into the slot machine. - Instead of displaying images, have the program randomly select a word from the following list: Cherries, Oranges, Plums, Bells, Melons, Bars (To select a word, the program can generate a random number in the range of 0 through 5. If the number is 0, the selected word is Cherries, if the number is 1, the selected word is Oranges, and so forth. The program should randomly select a word from the list three times and display all three of the words.) - If none of the randomly selected words match, the program informs the user that he or she has won $0. If two of the words match, the program informs the user that he or she has won two times the amount entered. If three of the words match, the program informs the user that he or she has won three times the amount entered. - The program asks if the user wants to play again. If so, these steps are repeated. If not, the program displays the total amount of money entered into the slot machine and the total amount won.
If you could just take a screen shot of the actual code on java that would be great. A lot of the characters appear differently when answer is copied and pasted on answer forum.
In: Computer Science
Discuss the following system development methods Structured development, Object oriented development, Agile development, and Rapid Application Development.
In: Computer Science
What are the main challenges for IOT management?
In: Computer Science
Python programming:
Instructions:
In: Computer Science
Write a C++ program that asks the user for the values of three resistances. We suppose that the user will not enter a negative value. The program then asks the user whether he has a series or parallel montage. The user will answer with S or s for series and P and p for parallel. (If the user enters a wrong answer, he will see a message on the screen alerting him, and the program will end.) Finally, the program displays the total resistance value. (Note that for a parallel circuit, if one of the resistances is zero, the total resistance is zero)
In: Computer Science
PHP Language
I have XAMPP and I don't know how to display my PHP code. For instance, when I create a basic HTML webpage I just open the code into a web browser and it shows me a basic web page. When I try to show a PHP calculation it doesn't show. What are the steps in displaying my PHP doc?
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
Task G. Checkerboard (3x3)
Write a program checkerboard3x3.cpp that asks the user to input width and height and prints a checkerboard of 3-by-3 squares. (It should work even if the input dimensions are not a multiple of three.) Don't use function. Please explain in detail and make it simple. And be clear with the {}. Thank you in advance.
Example 1:
Input width: 16 Input height: 11 Shape: *** *** *** *** *** *** *** *** *** *** *** * *** *** * *** *** * *** *** *** *** *** *** *** *** *** *** *** * *** *** *
Example 2:
Input width: 27 Input height: 27 Shape: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
In: Computer Science