Programming in C
4th Edition
ISBN: 9780321776419
Author: Stephen G. Kochan
Publisher: Addison-Wesley
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 4, Problem 6E
A minus sign placed in front of a field width specification causes the field to be displayed left-justified. Substitute the following p statement for the corresponding statement in
P
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
with python do this ( i only need the code, no need for explanation):
5. View user meals and generate health informationWhen the user chooses 5, the first thing that it should do is to check whether the user information is loaded in the program (i.e., check if the user information is passed to the function that generates recipe recommendations). If the user information is not passed to the function (i.e., the user did not chose option 1 before choosing option 4), call the function that allows the user to either load or create a user profile (option 1 from the main menu). Otherwise, perform the following tasks:• First, check the file username-recipes.txt exists, if the file does not exist, ask the user to generate recipes to view their health information, and call the function that allows the user to do so (i.e., call the function that shows choice 2 from the main menu).• If the file username-recipes.txt exists, open it in read mode and retrieve (i.e., read) all the information that…
Can you give me two ways to do it
Python question please include all steps and screenshot of code. Also please provide a docstring, and comments throughout the code, and test the given examples below. Thanks.
Implement function heads() that takes no input and simulates a sequence of coin flips.The simulation should continue as long as 'HEAD' is flipped. When the outcome of a flipis 'TAIL', the function should return the number of 'HEAD' flips made up to that point.For example, if the simulation results in outcomes 'HEAD', 'HEAD', 'HEAD', 'TAIL', thefunction should return 3. NOTE: Recall that random.choice(['HEAD', 'TAIL']) returns'HEAD' or 'TAIL' with equal probability.>>> heads()0 # TAIL is the outcome of the first coin flip>>> heads()2 # The coin flips were HEAD, HEAD, TAIL>>> heads()1 # The coin flips were HEAD, TAIL>>> heads()5 # The coin flips were HEAD, HEAD, HEAD, HEAD, HEAD, TAIL
Chapter 4 Solutions
Programming in C
Ch. 4 - Type in and run the nine programs presented in...Ch. 4 - Prob. 2ECh. 4 - A triangular number can also be generated by the...Ch. 4 - The factorial of an integer n. written n!, is the...Ch. 4 - The following perfectly valid C program was...Ch. 4 - A minus sign placed in front of a field width...Ch. 4 - A decimal point before the field width...Ch. 4 - Program 4.5 allows the user to type in only five...Ch. 4 - Rewrite Programs 4.2 through 4.5, replacing all...Ch. 4 - What would happen if you typed a negative number...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
To find the cube root (the third root) of a number, raise it to the power of 1/3. To find the fourth root of a ...
Starting Out with C++: Early Objects
Explain the difference between the WHERE and HAVING clause.
Modern Database Management (12th Edition)
What determines an objects appearance and other characteristics?
Starting Out With Visual Basic (7th Edition)
The spreadsheet in Microsoft Excel file Ch01Ex01_U10e.xlsx contains records of employee activity on special pro...
Using MIS (10th Edition)
PreferredCustomer Class A retail store has a preferred customer plan where customers can earn discounts on all ...
Starting Out with Java: Early Objects (6th Edition)
Restaurant Bill Write a program that computes the tax and tip on a restaurant bill. The program should ask the ...
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Please do only java file (FamilyName_CommodityCode.java) containingthe code and 4 image files (Sample1, Sample2, Sample3, and Sample4) containingdifferent sample input/output of the program.arrow_forwardPrint person1's kids, apply the IncNumKids() function, and print again, outputting text as below. End each line with a newline.Sample output for below program with input 3: Kids: 3 New baby, kids now: 4Only the solution goes here can be changed, the rest of the program cannot be messed with. --------------------c++ program below------ #include <iostream>using namespace std; class PersonInfo {public:void SetNumKids(int personsKidsToSet);void IncNumKids();int GetNumKids() const;private:int numKids;}; void PersonInfo::SetNumKids(int personsKidsToSet) {numKids = personsKidsToSet;} void PersonInfo::IncNumKids() {numKids = numKids + 1;} int PersonInfo::GetNumKids() const {return numKids;} int main() {PersonInfo person1;int personsKids; cin >> personsKids; person1.SetNumKids(personsKids); /* Your solution goes here */ return 0;}arrow_forwardWrite a function product or sum(num1, num2) that takes two int parameters and returns either their sum or their product, whichever is larger. In the first example below, the sum (17+ 1) is greater than the product (171), so the sum is returned. In the second example, the product (211) is greater than the sum (2+11), so the product is returned For example: Test Result print (product or sum(17, 1)) 18 print (product or sum(2, 11)) 22arrow_forward
- . . 1. Write a program that asks and prints student information (name, age, allowance per month). The number of students whose information must be collected will be stated at the start of program execution. After the inputting process, all student info will be displayed. A prompt will show telling the user if he/she wants to continue; if "Y/y", inputting student info will again commence; if "N/n", the program will terminate. Any inputs other than "Y/y" or "N/n" . STUDENT DETAIL DB Enter number of students: 2 . Enter Student 1 name: Karlo Cris Enter Student 1 age: 24 Enter Student 1 allowance per month: 20000 Enter Student 2 name: Yuan Kyrie Enter Student 2 age: 20 Enter Student 2 allowance per month: 15000 Student 1 Details ➖➖➖➖➖ Name: Karlo Cris Age: 24 Allowance Per Month: 20000.0 .... Student 2 Details will not be accepted and will loop to the prompt until a valid input is given. Coding Requirements: Name: Yuan Kyrie Age: 20 Allowance Per Month: 15000.0 Try again? (Y/N): G Invalid…arrow_forwardWrite a function that determines the type of its input variable and converts it into a character array, if it is numeric, or displays an error message if it is not numeric or character array. Please answer with code in MATLAB, thanks!arrow_forwardISP- Java Write a program that will output a right triangle based on user specified input height (int) and specified input symbol (char). The first line will have one user-specified character, such as % or *. Each subsequent line will have one additional user-specified character until the number in the triangle's base reaches specified input height. Output a space after each user-specified character, including after the line's last user-specified character. Hint: Use a nested for loop. Ex: If the input is: Enter a character: * Enter triangle height: 8 the output is: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *arrow_forward
- Write the loop condition and function body to complete the program below. The function should generate random (x,y) coordinates between 1-10, and return a Point object with those coordinates. This program randomly generates locations for two players, repeating until one of their coordinates are the same for both players. /* Here is the Sample Output your completed program should produce: This program randomly generates (x,y) locationsbetween 1-10 for two players, repeating untilone of their coordinates are the same for both players.Player1 location: (8,7)Player2 location: (2,9) Player1 location: (9,9)Player2 location: (4,1) Player1 location: (3,8)Player2 location: (3,8) This program randomly generates (x,y) locationsbetween 1-10 for two players, repeating untilone of their coordinates are the same for both players.Player1 location: (10,3)Player2 location: (3,1) Player1 location: (1,5)Player2 location: (9,2) Player1 location: (4,9)Player2 location: (7,1) Player1…arrow_forwardSolve using c programming. Show the code clearly with console output imagearrow_forward/*** The program below, while has the correct output, doesn't follow the game’s logic at all.* Instead, it follows a certain pattern that's present in the game.* Consider the 100th locker. Following the games rules, this locker should be visited by the 1st, 2nd,* 3rd, 4th, 5th, 10th, 20th, 25th, 50th, and 100th student. Coincidentally, these are also the positive* divisors of 100. Similarly, the 30th locker is visited by the students whose numbers are 1, 2, 3, 5,* 6, 10, 15, and 30. Note that if the numbers of positive divisors of a locker number is odd, then at* the end of the game, the locker is open. if the numbers of positive divisors of a locker number is* even, then at the end of the game, the locker is closed.*/import java.util.Random;public class Locker{public static void main(String[] args){Scanner keyboard = new Scanner(System.in);int studentVisitCount = 0;System.out.print("Enter the number of lockers: ");int numberOfLockers = console.nextInt();for(int x=0;…arrow_forward
- Python question please include all steps and screenshot of code. Also please provide a docstring, and comments throughout the code, and test the given examples below. Thanks. In written text small numbers are often written out, e.g. you'd write 'I have twobrothers and one sister', rather than 'I have 2 brothers and 1 sister'. In this problem youwill implement a function convertSmall() that takes as input a text (i.e., string) s andreturns the text s with small numbers (integers between 0 and 6) converted to their names.>>> convertSmall('I have 2 brothers and 1 sister')'I have two brothers and one sister'>>> convertSmall('I have 8 brothers and 5 sisters')'I have 8 brothers and five sisters'arrow_forward(a) A short description of your algorithm, where you explain the dynamic programing approach (see the sketch of the Algorithm below). More precisely, you need to indicate how you compute d[0] (this is the initialization step), and how you compute for every i ≥ 1, the value of d[i] using the values of some of the previous d[j]'s, for jarrow_forward1. In the game of Monopoly, a pair of dice are rolled to move a player's piece around the board. If a double is rolled (the dice show the same number), the player receives another roll of the dice. If a double is rolled a second time, a third roll of the dice is received. If a double is rolled on the third occasion, the player forfeits their turn (and goes to Jail). Write a program which simulates two players having 50 turns each (a turn however many dice rolls a player has in a row before it's the other player's turn) and determines: a) the total number of spaces moved by each player; and b) how many times a player rolls a double which results in movement of a piece. Use the randi function. For fun, incorporate the rule that a player cannot leave Jail (cannot move) unless they either roll a double or three turns have passed without rolling a double.arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Introduction to Operators in C; Author: Neso Academy;https://www.youtube.com/watch?v=50Pb27JoUrw;License: Standard YouTube License, CC-BY