6
.odt
keyboard_arrow_up
School
Southern New Hampshire University *
*We aren’t endorsed by this school
Course
145 X6485
Subject
Computer Science
Date
Dec 6, 2023
Type
odt
Pages
1
Uploaded by Ryanjordanl on coursehero.com
PARTICIPATION
acTviTy
6.2.3:
Formatting
floating point
outputs
using
printfi
Whatis
the
output
from
the
following
print
statements,
assuming
float
myFloat
=
45.1342F;
1)
System.out.printf("%+.5F",
myFloat);
+4513420
/
B3
oo
2)
System.out.printf("%.3e"
myFloat);
45138401
i
B2
oo
3)
System.out.printf("%09.2f",
myFloat);
00004513
/
Correct
+45.13420
ndicates
should
output before
a
positive
number,
and
5
indicates
5
digits
should
follow
the
decimal
pe
I
point.
Correct
4513e+01
at
values
in
scientific
notation,
print
following
the
decimal
point
Correct
imal
point,
and
2
e
output
wi
fewer
characters
than
the
width.
ers
are
printed:
6
digits
before
digits
after
the
0's
when
the
Feedback?
Discover more documents: Sign up today!
Unlock a world of knowledge! Explore tailored content for a richer learning experience. Here's what you'll get:
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
Language: JAVA
Problem 1: Decimal to Binary Conversion
Write a program that takes an integer value as an input and converts that value to its binary representation; for instance, if the user inputs 17, then the output will be 10001.
Do not forget to check for valid input, which means if the user inputs a type of data other than an integer re-prompt the user to enter a valid value. The output binary number can be a string.
Sample input and output:
Enter an integer > a
You entered an invalid type. Try again.
Enter an integer > 17
10001
arrow_forward
AIM- Write an 8085 sequence to check whether the first set of
reading is higher than the second one or not.
PROBLEM STATEMENT- The pressure of two boilers is monitored and
controlled by a microcomputer works based on microprocessor
programming. A set of 6 readings of first boiler, recorded by six
pressure sensors, which are stored in the memory location starting
from 2050H. A corresponding set of 6 reading from the second boiler
is stored at the memory location starting from 2060H. Each reading
from the first set is expected to be higher than the corresponding
position in the second set of readings. Write an 8085 sequence to
check whether the first set of reading is higher than the second one
or not. If all the readings of first set is higher than the second set,
store 00 in the 'D' register. If any one of the readings is lower than
the corresponding reading of second set, stop the process and store
FF in
the register 'D'.
Data (H): First set: 78, 89, 6A, 80, 90, 85
Second Set:71, 78,…
arrow_forward
Using the following description, please replace the return line in C code;
/*
* logicalShift: logical shift x to the right by n,
* where 0 <= n <= 31
* Examples:
* logicalShift(0xFFFFFFFF,0) = 0xFFFFFFFF
* logicalShift(0xFFFFFFFF,1) = 0x7FFFFFFF
* logicalShift(0xFFFFFFFF,2) = 0x3FFFFFFF
* logicalShift(0xFFFFFFFF,3) = 0x1FFFFFFF
* logicalShift(0xFFFFFFFF,4) = 0x0FFFFFFF
* logicalShift(0xFFFFFFFF,8) = 0x00FFFFFF
* logicalShift(0xFFFFFFFF,12) = 0x000FFFFF
* Legal ops: ! ~ & ^ | + << >>
* Max ops: 20
* Rating: 3
* Hints/notes:
*
*/
int logicalShift(int x, int n) {
return 2
}
You cannot:
1. Use any control constructs such as if, do, while, for, switch, etc.
2. Define or use any macros.
3. Define any additional functions in this file.
4. Call any functions.
5. Use any other operations, such as &&, ||, -, or ?:, not listed in the
the "Legal ops" list for the function.
6. Use any form of casting.
7. Use any data type other than int.
arrow_forward
Assignment
Write a program in C that converts temperatures between Fahrenheit, Celsius, and Kelvin.
Functional Requirements
• MUST correctly convert temperatures between scales
• MUST read input by prompting the user
Nonfunctional Requirements
• MUST compile without warnings and errors
• MUST print error message "Invalid temperature scale" on invalid input
• MUST return 0 on success
• MUST return non-0 value on failure
Sample run
$ ./temp
Enter input temperature: 18c
18.00 C converts to:
64.40 F
291.15 Κ
The conversion formulas are listed below:
Celsius = (Fahrenheit - 32) / 1.8
Kelvin = Celcius + 273.15
arrow_forward
6.use c code to Develop a code that gets two integers from the user and calculates and prints their least common multiplier or LCM. LCM is the smallest number that divides both given integers.
Example.
lcm (10, 15) = 30, lcm (5,7) = 35 and lcm (12, 24) = 24Hint: we know that lcm(x,y) = xy/gcd(x,y) where gcd is the greatest common divisor (discussed in class). Develop a gcd function in your code, get the two numbers from the user, call your function to calculate their gcd and then use the formula above to calculate and display their lcm
GOOD LUCK!
Reference
This is a list of function prototypes of the C library functions presented in class. You may use any of these functions in your solutions (unless the requirements explicitly indicate otherwise). As you have been provided the function prototypes, you are expected to use the functions correctly in your solutions.
double atof(char *string);
int atoi(char *string);
long atol(char *string);
int fclose(FILE *filePointer);
char *fgets(char…
arrow_forward
Reverse integer (requires use of INT_MAX)
Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.
Assume the environment does not allow you to store 64-bit integers (signed or unsigned).
Code in Java
A brief explanation of how and why your code works and how it relates to the concepts learned (for example, it uses bitwise operation, stack, or takes into account a word size).
arrow_forward
Define the function:
int power (int base, int exp)
{/*It accepts the arguments for base and exponent and returns power. The algorithm is to repeatedly multiply the value of the base to how many times the value of exponent. Test the function inside main(). Write the complete C program. */}
For example:
Intput. Result
2 32
5
arrow_forward
Enter an integer: -29
-29 is negative and odd!
// OUTPUT Sample Run #2
We write code to manipulate data, which are
provided by the user(s), to produce the
required outcome in the most efficient way!
CIS 25 Fall 2023 - Homework #1 - Page 5 of 7
CIS 25 C++ Programming
Laney College
Your Name
Information
Assignment:
Implemented by:
Required Submission Date:
Actual Submission Date:
CIS 25 C++ Programming
Laney College
Your Name
Enter an integer: -294258
-294257 is negative and even!
// OUTPUT Sample Run #3
We write code to manipulate data, which are
provided by the user(s), to produce the
required outcome in the most efficient way!
Information
--
Assignment:
Implemented by:
Required Submission Date:
Actual Submission Date:
HW #1 Exercise #1
Your Name
2023/09/18
JJ-
CIS 25 - C++ Programming
Laney College
Your Name
HW #1 Exercise #1
Your Name
2023/09/18
Enter an integer: 41294258
41294258 is positive and even!
// OUTPUT Sample Run #4
We write code to manipulate data, which are
provided by…
arrow_forward
PaoBLEM# 39 I Simplify the following expressions using Boolean
algebra. Cite the laws and therorems used.
• AB + A(CD + CD')
• (BC' + A'D) (AB' + CD')
arrow_forward
===========Answer question below:===========
- Write program in Java.
(Convert infix to postfix)
Note:
Postfix notation is a way of writing expression without using parentheses. For example, the expression ( 11 + 12 ) * 13 would be written as 11 12 + 13 *
Assume that ALWAYS there is a space between operands and operators in the input expression.
Use two stacks, one to store the operands and one to store the operators.
Your program only accpets following operators :
( )
+
-
/
*
Write a method to converts an infix expression into a postfix expression using the following method:
String infixToPostfix(String expression)
For example, the method should convert the infix expression
( 13 + 25 ) * 34 to 13 25 + 34 *
and
20 * ( 10 + 30 ) to 20 10 30 + *.
- solution.java:
import java.util.*;
import java.lang.*;
import java.io.*;
class InfixToPostfix {
public String infixToPostfix(String expression) {
}
}
class DriverMain {
public static void main(String args[]) {
Scanner input…
arrow_forward
2. Find the errors to print the following series:
6.1 6.4
6.7
7.0
7.3
7.6
7.9
int i;
for ( i= 6.1, i> z ;
}
arrow_forward
int power(int base,int exp);
*This function accepts the
arguments for base and exponent
and returns power. The algorithm is
to repeatedly multiply the value of
the base to how many time the value
of exponent.*
For example:
Test Input Result
printf("%d",power(2,5)); 2 32
5
printf("%d",power(3,4)); 3 81
4
-Use C language, please. Thank you.
arrow_forward
|%Y0 l. lin. e
Z. Clean Code
time limit per test: 1 seconde
memory limit per test: 256 megabytes
input: standard input
output: standard output
Given a source code in C++. Print the source code after cleaning it as follows :
1. If there are comments you have to remove them all whether it's a single
comment (e.g. : //) or a block comment (e.g.: /**/).
2. If there are any blank lines or lines consists of spaces you must remove them
all.
See the test cases carefully for more clarifications.
Input
Source code in C++ (maximum number of lines is 50).
Output
Print the clean code according to the problem statement.
Example
input
Соpy
// I am a single comment and you must remove me : ((
I am a block comment and you must remove me
* /
#include
using namespace std;
int main () {
int a, b;
cin
a » b; // Reading two variables from user (please remove
>>
me !! :
cout «
а + b « endl:
// End of the program (remove me please :) )
return 0 ;
output
Соpy
#include
using namespace std;
int main () {
int a,…
arrow_forward
Change this code into a program that receives a number and prints its divisors.( C language)
#include <stdio.h>
int main()
{
unsigned guess; /* current guess for prime */
unsigned factor; /* possible factor of guess */
unsigned limit; /* find primes up to this value */
printf("Find primes up to: ");
scanf("%u", &limit);
printf("2\n"); /* treat first two primes as special case */
printf("3\n");
guess = 5; /* initial guess */
while ( guess <= limit ) {
/* look for a factor of guess */
factor = 3;
while ( factor*factor < guess && guess % factor != 0 )
factor += 2;if ( guess % factor != 0 )
printf("%d\n", guess);
guess += 2; /* only look at odd numbers */
}
return 0;
}
arrow_forward
Consider the following C++ code snippet:
int cards[3];
for (int i = 0; i < 3; i++)
cards[i] = 0;
Choose the best statement:
A) This code will compile and run but causes an out-of-range memory write.
B) This code will compile and has no apparent issues.
C) This code will not compile as written.
D) This code shows an example of dynamic memory allocation.
arrow_forward
C++ Programming Language: Enhance the code given by outputting:
The largest number of the sequence a0 ,a1 ,a2 , ..., ak.
The position of the largest number
Test your program for the following values of x: 75, 111, 678, 732, 873, 2048, and 65535.
Example:
"For example, for the input sequence: 75, 226, 113, 340, 170, 85, 256, 128, 64, 32, 16, 8, 4, 2, 1, the program output should contain the following:
The largest number of the sequence is 340 The position of the largest number is 4"
Code Given:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
long x;
int count;
long a_n;
cout << "Enter a nonnegative integer: ";
cin >> x;
cout << endl;
count = 0;
a_n = x;
cout << a_n << ", ";
while (a_n !=1)
{
if (a_n %2==0)
a_n = a_n / 2;
else
a_n = 3 * a_n + 1;
count++;
cout << a_n <<", ";
}
cout << endl;
cout << "The integer k such that a_k = 1 is " << count << endl;
return0;
}
arrow_forward
PROBLEM:
Write a program that computes the equivalent resistance of a purely series and purely parallel electric
circuit.
SPECIFICATIONS:
• The program will ask the user to choose whether to compute for the equivalent resistance of a series
or parallel combination.
• The user will input three resistance values R1, R2, and R3 in ohms.
• The program will provide an output of equivalent resistance in series (Rs) or parallel (Rp).
• You may only use the codes that we studied in our lectures.
• All lines of codes should have a comment.
To recall, the formula for solving the resistance for a purely series and purely parallel circuit are:
a. Series Circuit:
R1
120 ohms
R2
Vs
100 V
Rs = R7 = R1 + R2 + R3 + …+ Rn
...
30 ohms
R3
50 ohms
b. Parallel Circuit:
1
1
1
+
R1' R2 ' R3
1
1
1
...
Rp
RT
Rn
R1
R2
10 ohms
Vs
40 ohms
40 Volts
TEST CASES:
If the user inputs a character:
Computing for the equivalent resistance
A. Series Combination
B. Parallel Combination
Enter Choice: B
Enter R1: 1
Enter R2: 2…
arrow_forward
Program this one
arrow_forward
jmp *(%eax) uses the value in register %eax as the jump target
true or false?
arrow_forward
Analyze the following program fragment:
int x;
int d = 4;
switch (d) {
case 4: x = 4;
case 0: x = 0;
case 2: x = 2;
O The program has a compile error because the required default case is missing.
O The program has a compile error because case must be ordered from smallest to largestes.
The programs compiles and runs fine.
O The program has a compile error because the break statements are missing..
arrow_forward
Program this
arrow_forward
*Modify the program so that the user will error trap for only 1 and 0 as an input.
*If the user enters an input other than 1 or 0 display an error message and request the user enter that input again.
*Do this for all inputs in the code.
# User defined function for logic OR# The function takes two parameters and returns a single intdef OR(a: int, b: int)->int:# If a is equal to 1 return 1if a == 1 :return 1# If b is equal to 1 return 1elif b == 1 :return 1# If a and b is equal to 0 return 0else :return 0
# User defined function for logic NOR# The function takes two parameters and returns a single intdef NOR(a: int, b: int)->int:# If a is equal to 0 and b is also equal to 0 return 1if a == 0 and b == 0 :return 1# If a is equal to 0 and b is equal to 1 return 0elif a == 0 and b == 1 :return 0# If a is equal to 1 and b is also equal to 0 return 0elif a == 1 and b == 0 :return 0# If a is equal to 1 and b is also equal to 1 return 0elif a == 1 and b == 1 :return 0
# User defined…
arrow_forward
Generate test cases for the following
code by using MC/DC.
a) Draw the CFG.
b) What is MC/DC logic coverage
criteria?
c)
List the test cases.
d) Validate the test cases can
achieve MC/DC.
public void TestValues( int a, int b,
ref int x)
{
}
x = 0;
if (a> 0 || b 10 && b > 10)
x = -1;
arrow_forward
Write the following
arrow_forward
Programming Language: Python 4. Write a Python function that will take a positive integer n from the user as an argument and returns the largest power of two greater than or equal to n.
arrow_forward
Explain what the following code does. (Hint: You can explain each line)
bool SensorTrigger(int);
bool FLAG= SensorTrigger (0x0a22);
int InjectionData = 0;
for (unsigned int i=0; i 200 && FLAG) InjectionData = 0;
cout
arrow_forward
:Create the logic for the dice game Pig, in which a player can compete with the computer. The objectof the game is to be the first to score 100 points. The user and computer take turns “rolling” a pair of dicefollowing these rules:• On a turn, each player rolls two dice. If no 1 appears, the dice values are added to a running total for theturn, and the player can choose whether to roll again or pass the turn to the other player. When a player passes,the accumulated turn total is added to the player’s game total.• If a 1 appears on one of the dice, the player’s turn total becomes 0; in other words, nothing more isadded to the player’s game total for that turn, and it becomes the other player’s turn.• If a 1 appears on both of the dice, not only is the player’s turn over, but the player’s entire accumulatedtotal is reset to 0.• When the computer does not roll a 1 and can choose whether to roll again, generate a random valuefrom 1 to 2. The computer then will decide to continue when the…
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Related Questions
- Language: JAVA Problem 1: Decimal to Binary Conversion Write a program that takes an integer value as an input and converts that value to its binary representation; for instance, if the user inputs 17, then the output will be 10001. Do not forget to check for valid input, which means if the user inputs a type of data other than an integer re-prompt the user to enter a valid value. The output binary number can be a string. Sample input and output: Enter an integer > a You entered an invalid type. Try again. Enter an integer > 17 10001arrow_forwardAIM- Write an 8085 sequence to check whether the first set of reading is higher than the second one or not. PROBLEM STATEMENT- The pressure of two boilers is monitored and controlled by a microcomputer works based on microprocessor programming. A set of 6 readings of first boiler, recorded by six pressure sensors, which are stored in the memory location starting from 2050H. A corresponding set of 6 reading from the second boiler is stored at the memory location starting from 2060H. Each reading from the first set is expected to be higher than the corresponding position in the second set of readings. Write an 8085 sequence to check whether the first set of reading is higher than the second one or not. If all the readings of first set is higher than the second set, store 00 in the 'D' register. If any one of the readings is lower than the corresponding reading of second set, stop the process and store FF in the register 'D'. Data (H): First set: 78, 89, 6A, 80, 90, 85 Second Set:71, 78,…arrow_forwardUsing the following description, please replace the return line in C code; /* * logicalShift: logical shift x to the right by n, * where 0 <= n <= 31 * Examples: * logicalShift(0xFFFFFFFF,0) = 0xFFFFFFFF * logicalShift(0xFFFFFFFF,1) = 0x7FFFFFFF * logicalShift(0xFFFFFFFF,2) = 0x3FFFFFFF * logicalShift(0xFFFFFFFF,3) = 0x1FFFFFFF * logicalShift(0xFFFFFFFF,4) = 0x0FFFFFFF * logicalShift(0xFFFFFFFF,8) = 0x00FFFFFF * logicalShift(0xFFFFFFFF,12) = 0x000FFFFF * Legal ops: ! ~ & ^ | + << >> * Max ops: 20 * Rating: 3 * Hints/notes: * */ int logicalShift(int x, int n) { return 2 } You cannot: 1. Use any control constructs such as if, do, while, for, switch, etc. 2. Define or use any macros. 3. Define any additional functions in this file. 4. Call any functions. 5. Use any other operations, such as &&, ||, -, or ?:, not listed in the the "Legal ops" list for the function. 6. Use any form of casting. 7. Use any data type other than int.arrow_forward
- Assignment Write a program in C that converts temperatures between Fahrenheit, Celsius, and Kelvin. Functional Requirements • MUST correctly convert temperatures between scales • MUST read input by prompting the user Nonfunctional Requirements • MUST compile without warnings and errors • MUST print error message "Invalid temperature scale" on invalid input • MUST return 0 on success • MUST return non-0 value on failure Sample run $ ./temp Enter input temperature: 18c 18.00 C converts to: 64.40 F 291.15 Κ The conversion formulas are listed below: Celsius = (Fahrenheit - 32) / 1.8 Kelvin = Celcius + 273.15arrow_forward6.use c code to Develop a code that gets two integers from the user and calculates and prints their least common multiplier or LCM. LCM is the smallest number that divides both given integers. Example. lcm (10, 15) = 30, lcm (5,7) = 35 and lcm (12, 24) = 24Hint: we know that lcm(x,y) = xy/gcd(x,y) where gcd is the greatest common divisor (discussed in class). Develop a gcd function in your code, get the two numbers from the user, call your function to calculate their gcd and then use the formula above to calculate and display their lcm GOOD LUCK! Reference This is a list of function prototypes of the C library functions presented in class. You may use any of these functions in your solutions (unless the requirements explicitly indicate otherwise). As you have been provided the function prototypes, you are expected to use the functions correctly in your solutions. double atof(char *string); int atoi(char *string); long atol(char *string); int fclose(FILE *filePointer); char *fgets(char…arrow_forwardReverse integer (requires use of INT_MAX) Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0. Assume the environment does not allow you to store 64-bit integers (signed or unsigned). Code in Java A brief explanation of how and why your code works and how it relates to the concepts learned (for example, it uses bitwise operation, stack, or takes into account a word size).arrow_forward
- Define the function: int power (int base, int exp) {/*It accepts the arguments for base and exponent and returns power. The algorithm is to repeatedly multiply the value of the base to how many times the value of exponent. Test the function inside main(). Write the complete C program. */} For example: Intput. Result 2 32 5arrow_forwardEnter an integer: -29 -29 is negative and odd! // OUTPUT Sample Run #2 We write code to manipulate data, which are provided by the user(s), to produce the required outcome in the most efficient way! CIS 25 Fall 2023 - Homework #1 - Page 5 of 7 CIS 25 C++ Programming Laney College Your Name Information Assignment: Implemented by: Required Submission Date: Actual Submission Date: CIS 25 C++ Programming Laney College Your Name Enter an integer: -294258 -294257 is negative and even! // OUTPUT Sample Run #3 We write code to manipulate data, which are provided by the user(s), to produce the required outcome in the most efficient way! Information -- Assignment: Implemented by: Required Submission Date: Actual Submission Date: HW #1 Exercise #1 Your Name 2023/09/18 JJ- CIS 25 - C++ Programming Laney College Your Name HW #1 Exercise #1 Your Name 2023/09/18 Enter an integer: 41294258 41294258 is positive and even! // OUTPUT Sample Run #4 We write code to manipulate data, which are provided by…arrow_forwardPaoBLEM# 39 I Simplify the following expressions using Boolean algebra. Cite the laws and therorems used. • AB + A(CD + CD') • (BC' + A'D) (AB' + CD')arrow_forward
- ===========Answer question below:=========== - Write program in Java. (Convert infix to postfix) Note: Postfix notation is a way of writing expression without using parentheses. For example, the expression ( 11 + 12 ) * 13 would be written as 11 12 + 13 * Assume that ALWAYS there is a space between operands and operators in the input expression. Use two stacks, one to store the operands and one to store the operators. Your program only accpets following operators : ( ) + - / * Write a method to converts an infix expression into a postfix expression using the following method: String infixToPostfix(String expression) For example, the method should convert the infix expression ( 13 + 25 ) * 34 to 13 25 + 34 * and 20 * ( 10 + 30 ) to 20 10 30 + *. - solution.java: import java.util.*; import java.lang.*; import java.io.*; class InfixToPostfix { public String infixToPostfix(String expression) { } } class DriverMain { public static void main(String args[]) { Scanner input…arrow_forward2. Find the errors to print the following series: 6.1 6.4 6.7 7.0 7.3 7.6 7.9 int i; for ( i= 6.1, i> z ; }arrow_forwardint power(int base,int exp); *This function accepts the arguments for base and exponent and returns power. The algorithm is to repeatedly multiply the value of the base to how many time the value of exponent.* For example: Test Input Result printf("%d",power(2,5)); 2 32 5 printf("%d",power(3,4)); 3 81 4 -Use C language, please. Thank you.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,