Write the equations for carry-out bits for a 4-bit carry lookahead adder. Draw its diagram and label all the inputs and the outputs. Compare the delays of the 4-bit ripple-carry and 4-bit carry lookahead adders.
In: Computer Science
Write a C program that counts the number of odd numbers with using function count() within the set. The set has only one negative number which determines the end of set.
In: Computer Science
(previous program) Prompt the user for the filename. Create a new file object sensehat_data_file which opens the file in write mode. Write a loop which will read in 20 values for temperature and humidity from the SenseHat. Sleep 0.5 seconds between each reading taken from the SenseHat Write out the temperature and humidity to the file sensehat_data_file, separated by a comma. Close the file.)
ONLY ANWSER problem below
Then Open the file in read only mode. Use a loop to read in the data from the file until all lines have been read. Print out the count for the number of the line read in. Print out the temperature and humidity.
Print in Python .
In: Computer Science
6. There are 3 types of positioning commands in CSS: static, relative, and absolute. Explain how each type behaves with regard to: (a) (2 pts) whether or not offsets can be specified (b) (2 pts) where offset values are measured from
In: Computer Science
Write a Java application for a gas station to calculate the total payment for customer.
Your program should display a menu and get customer’s input: ****************************
Welcome to XYZ gas station! Select type of gas (enter R, P, S) Regular - R. plus - P. Super -S: ****************************
Enter the amount of gas in gallons:
In your code, define regular price: $2.45, plus: $2.65, super $2.95 as constant.
Use 7% as sale tax.
Calculate gas subtotal = sale price * gas amount Tax=subtotal * sale tax. Total payment = subtotal + Tax Output nicely to customer the total amount payment:
######################################################
Your payment for (Regular/plus/Super) is $###.
######################################################
Requirements:
Use switch statement for type of gas (case ‘R’, case ‘P’, case ‘S’ , etc)
Use while loop to display the menu. If user inputs anything other than R,P,S, display the menu again.
Use for loop statement to draw lines(**********… and ##############...)
In: Computer Science
In: Computer Science
For this assignment, you will be analyzing the Java™ code in the linked Week 3 Analyze Assignment Zip File, and predicting the results. You will also examine both the code and the output for inconsistencies and clarity. This Java™ code includes examples of for, while, and do-while loops.
Carefully read through the code line by line, then answer the following questions in a Microsoft® Word document:
Note: You do not have to make the improvements in the Java™ program, although you certainly may. For this assignment, simply describe the things you see that would need to be improved to elevate the code and output to a more professional level. For the code, consider variable names and hardcoding. For the output, consider formatting/punctuation, repetition, accuracy of information, and wording.
/**************************************************************************************
* Program: PRG/420 Week 3
* Purpose: Week 3 Analyze Assignment
* Programmer: Iam A. Student
* Class: PRG/420
* Creation Date: 10/22/17
******************************************************************************************
* Program Summary: For, while, and do-while loops
*
* This program demonstrates the syntax for the for, while, and
do-while loops. It also
* contains comments that explain why a programmer would use a for
loop over a while or do-while
* loop.
*
* Notice the increment operator (i++) and also notice the copious
use of println() statements.
* Using System.out.println() is an excellent way to debug your
code--especially if your loop code
* is giving unexpected results.
*****************************************************************************************/
package PRG420Week3_AnalyzeAssignment;
public class PRG420Week3_AnalyzeAssignment {
public static void main(String[] args) {
// for loops are a good choice when you have a specific number of
values
// you want to iterate over and apply some calculation to.
System.out.println("FOR LOOP - Here are the taxes on all 10
prices:");
double taxRate = 0.08;
for (int price=1; price<=10; price++) {
System.out.println("The 8% tax on " + price + " dollar(s) is " +
"$" + (price * taxRate));
}
System.out.println(""); // Leave a blank space
// while loops are a good choice when you're looking through a pile
of values
// and want to execute some logic while some condition is
true.
// while loops MAY OR MAY NOT EVER EXECUTE, depending on the
counter value.
int dollars=1;
System.out.println("WHILE LOOP - Here are the taxes on prices less
than $5:");
while (dollars < 5) {
System.out.println("The 8% tax on " + dollars + " dollar(s) is $" +
(dollars * taxRate));
dollars++;
}
System.out.println(""); // Leave a blank space
// do-while loops are also a good choice when you're looking
through a pile of values
// and want to execute some logic while some condition is
true.
// do while loops ALWAYS EXECUTE AT LEAST ONCE, no matter what the
counter value.
// For example, in the code below, we want to print out the tax
only on those
// amounts smaller than $1. But because we're using the do-while
loop, the code
// will execute the body of the loop once before it even checks the
condition! So
// we will get an INCORRECT PRINTOUT.
dollars=1;
System.out.println("DO-WHILE LOOP - Here are the taxes on prices
less than $1:");
do {
System.out.println("The 8% tax on " + dollars + " dollar(s) is $" +
(dollars * 0.08));
dollars++;
} while (dollars < 1);
}
}
In: Computer Science
Assignment (C language)
We will simulate the status of 8 LEDs that are connected to a microcontroller. Assume that the state of each LED (ON or OFF) is determined by each of the bits (1 or 0) in an 8-bit register (high-speed memory).
HINTS:
In: Computer Science
Use counting sort, sort the following numbers: 4, 2, 5, 4, 2, 3, 0, 2, 4, 3
In: Computer Science
Objective:
Write this program in the C programming language
Loops with input, strings, arrays, and output.
Assignment:
It’s an organization that accepts used books and then sells them a couple of times a year at book sale events. Some way was needed to keep track of the inventory.
You’ll want two parallel arrays: one to keep track of book titles, and one to keep track of the prices. Assume there will be no more than 10 books. Assume no more than 100 characters per book title title. Use malloc to allocate the strings in the array.
So, it will be a menu:
In: Computer Science
How do you implement an AVL tree for strings in Java?
In: Computer Science
Write a Python program that draw simple lollipop (a line and few circles, the line should attach to the circle, just as regular lollipop, you decide the colors),
In: Computer Science
Change the program to modify the output file by making each sentence a new paragraph (inserting two carriage returns between every sentence. :) Don't over-think this, but you must have worked through and understand how the program works now in order to modify it. Remember, you want the carriage returns between every SENTENCE, not every LINE.
How would one do this? I'm not to sure how to make it make a new line after a sentence. Any help will be appreciated.
This is the original code that makes it make a new line after every carriage return. I need it to make a new line after every sentence.
Here is the input text file :
Today we live in an era where information is processed
almost at the speed of light. Through computers, the
technological revolution is drastically changing the way we
live and communicate with one another. Terms such as
“the Internet,” which was unfamiliar just a few years ago,
are
very common today. With the help of computers you can send
letters to, and receive letters from, loved ones within
seconds. You no longer need to send a résumé by mail to apply
for a job; in many cases you can simply submit your job
application via the Internet. You can watch how stocks
perform
in real time, and instantly buy and sell them. Students
regularly “surf” the Internet and use computers to design
their classroom projects. They also use powerful word
processing software to complete their term papers. Many
people maintain and balance their checkbooks on computers.
Sorry the last question i posted looked very ugly!!
//*************************************************************
// Author: D.S. Malik
//
// Program: Line and Letter Count
// This program reads a text, outputs the text as is, and
also
// prints the number of lines and the number of times each
// letter appears in the text. An uppercase letter and a
// lowercase letter are treated as being the same; that is,
// they are tallied together.
//*************************************************************
#include
#include
#include
using namespace std;
void initialize(int& lc, int list[]);
void characterCount(char ch, int list[]);
void copyText(ifstream& intext, ofstream& outtext,
char& ch,
int list[]);
void writeTotal(ofstream& outtext, int lc, int list[]);
int main()
{
//Step 1; Declare variables
int lineCount;
int letterCount[26];
char ch;
ifstream infile;
ofstream outfile;
infile.open("textin.txt"); //Step 2
if (!infile) //Step 3
{
cout << "Cannot open the input file."
<< endl;
return 1;
}
outfile.open("textout.out"); //Step 4
initialize(lineCount, letterCount); //Step 5
infile.get(ch); //Step 6
while (infile) //Step 7
{
copyText(infile, outfile, ch, letterCount); //Step 7.1
lineCount++; //Step 7.2
infile.get(ch); //Step 7.3
}
writeTotal(outfile, lineCount, letterCount); //Step 8
infile.close(); //Step 9
outfile.close(); //Step 9
return 0;
}
void initialize(int& lc, int list[])
{
int j;
lc = 0;
for (j = 0; j < 26; j++)
list[j] = 0;
} //end initialize
void characterCount(char ch, int list[])
{
int index;
ch = toupper(ch); //Step a
index = static_cast(ch)
- static_cast('A'); //Step b
if (0 <= index && index < 26) //Step c
list[index]++;
} //end characterCount
void copyText(ifstream& intext, ofstream& outtext,
char& ch,
int list[])
{
while (ch != '\n') //process the entire line
{
outtext << ch; //output the character
characterCount(ch, list); //call the function
//character count
intext.get(ch); //read the next character
}
outtext << ch; //output the newline character
} //end copyText
void writeTotal(ofstream& outtext, int lc, int list[])
{
int index;
outtext << endl << endl;
outtext << "The number of lines = " << lc <<
endl;
for (index = 0; index < 26; index++)
outtext << static_cast(index + static_cast('A'))
<< " count = " << list[index] << endl;
} //end writeTotal
This is the code I've got so far to make it ask for what the output file should be named.
//*************************************************************
// Author: D.S. Malik
//
// Program: Line and Letter Count
// This program reads a text, outputs the text as is, and
also
// prints the number of lines and the number of times each
// letter appears in the text. An uppercase letter and a
// lowercase letter are treated as being the same; that is,
// they are tallied together.
//*************************************************************
#include
#include
#include
using namespace std;
void initialize(int& lc, int list[]);
void characterCount(char ch, int list[]);
void copyText(ifstream& intext, ofstream& outtext,
char& ch,
int list[]);
void writeTotal(ofstream& outtext, int lc, int list[]);
int main()
{
//Step 1; Declare variables
int lineCount;
int letterCount[26];
char ch;
ifstream infile;
ofstream outfile;
string fileName;
infile.open("textin.txt"); //Step 2
if (!infile) //Step 3
{
cout << "Cannot open the input file."
<< endl;
return 1;
}
cout << "Please enter the name of the output file: ";
<----- This is the new code
getline(cin, fileName); <----- This is the new code
outfile.open(fileName.c_str()); //Step 4 <----- This is the new
code
initialize(lineCount, letterCount); //Step 5
infile.get(ch); //Step 6
while (infile) //Step 7
{
copyText(infile, outfile, ch, letterCount); //Step 7.1
lineCount++; //Step 7.2
infile.get(ch); //Step 7.3
}
writeTotal(outfile, lineCount, letterCount); //Step 8
infile.close(); //Step 9
outfile.close(); //Step 9
return 0;
}
void initialize(int& lc, int list[])
{
int j;
lc = 0;
for (j = 0; j < 26; j++)
list[j] = 0;
} //end initialize
void characterCount(char ch, int list[])
{
int index;
ch = toupper(ch); //Step a
index = static_cast(ch)
- static_cast('A'); //Step b
if (0 <= index && index < 26) //Step c
list[index]++;
} //end characterCount
void copyText(ifstream& intext, ofstream& outtext,
char& ch,
int list[])
{
while (ch != '\n') //process the entire line
{
outtext << ch; //output the character
characterCount(ch, list); //call the function
//character count
intext.get(ch); //read the next character
}
outtext << ch; //output the newline character
} //end copyText
void writeTotal(ofstream& outtext, int lc, int list[])
{
int index;
outtext << endl << endl;
outtext << "The number of lines = " << lc <<
endl;
for (index = 0; index < 26; index++)
outtext << static_cast(index + static_cast('A'))
<< " count = " << list[index] << endl;
} //end writeTotal
In: Computer Science
In a file called ThreeOperations.java, write a program that:
For example: if the user enters numbers 11 and 7, your program output should look EXACTLY like this:
Please enter real number N1: 11 Please enter real number N2: 7 11.000000 * 7.000000 = 77.00 11.000000 / 7.000000 = 1.57 11.000000 raised to the power of 7.000000 = 19487171.00
As another example: if the user enters numbers 3.25 and 10.3, your program output should look EXACTLY like this:
Please enter real number N1: 3.25 Please enter real number N2: 10.3 3.250000 * 10.300000 = 33.48 3.250000 / 10.300000 = 0.32 3.250000 raised to the power of 10.300000 = 187239.99
In: Computer Science
import java.io.*;
import java.util.*;
/**
*
*
*
*
* Lab Project 9: Rock, Paper, Scissors
*
* @authors *** Replace with your names here ***
*/
public class lab
{
// global named constant for random number generator
static Random gen = new Random();
// global named constants for game choices
static final int ROCK = 1;
static final int PAPER = 2;
static final int SCISSORS = 3;
// global names constants for game outcomes
static final int PLAYER1_WINS = 11;
static final int PLAYER2_WINS = 12;
static final int DRAW = 3;
// global named constant for error condition
static final int ERROR = -1;
/**
* 1. Get human player's choice
* 2. Get computer player's (random) choice
* 3. Check human player's choice
* 4. Check computer player's choice
* 5. Announce winner
*/
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
PrintStream output = System.out;
int player1, player2;
// get player 1 input as 1 (rock), 2 (paper or 3 (scissors)
output.print("Choose 1 (rock), 2 (paper), or 3 (scissors): ");
player1 = scan.nextInt();
/* Lab 9.1
*
* *** Add code here to validate that player1 has entered
* an integer between 1 and 3
* otherwise, ABORT the program
*/
// echo human player's choice
System.out.print(" You chose ");
if (player1 == ROCK) { System.out.println("rock"); }
else if (player1 == PAPER) { System.out.println("paper"); }
else { System.out.println("scissors"); }
// now computer picks one randomly
output.println("Now I choose one ...");
/*
Lab 9.2
*** Add code to and un-comment the following line so that
player2 is set to a random integer between 1 and 3,
using the gen Random object, ALREADY DECLARED AS
A GLOBAL VARIABLE:
*/
// player2 = ...;
System.out.print(" I choose ");
/* Lab 9.3
*
* *** Add code here to output the computer's choice
* as "rock", "paper" or "scissors"
*/
/* Lab 9.4
*
* *** Add code below to compare player input against
* computer's choice and output results:
*
* if human player chose ROCK:
* call rockChoice method with computer choice
* output the game's outcome (returned from rockChoice)
* otherwise, if human player chose PAPER:
* call paperChoice method with computer choice
* output the game's outcome (returned from paperChoice)
* otherwise, if human player chose SCISSORS:
* call scissorcChoice method with computer choice
* output the game's outcome (returned from scissorcChoice)
*/
} // end main
/**
* Lab 9.5
*
* rockChoice(int) -> int
*
* method consumes the computer player's choice (ROCK, PAPER or SCISSORS),
* assuming the human player has chosen ROCK
* method produces game outcome (PLAYER1_WINS, PLAYER2_WINS, or DRAW)
*
* ex1: rockChoice(ROCK) -> DRAW
* ex2: rockChoice(PAPER) -> PLAYER2_WINS
* ex3: rockChoice(SCISSORS) -> PLAYER1_WINS
* ex4: rockChoice(0) -> ERROR
* ex5: rockChoice(-1) -> ERROR
* ex6: rockChoice(4) -> ERROR
*
* *** ADD METHOD CODE HERE ***
*/
/**
* Lab 9.6
*
* paperChoice(int) -> int
*
* method consumes the computer player's choice (ROCK, PAPER or SCISSORS),
* assuming the human player has chosen PAPER
* method produces game outcome (PLAYER1_WINS, PLAYER2_WINS, or DRAW)
*
* ex1: paperChoice(ROCK) -> PLAYER1_WINS
* ex2: paperChoice(PAPER) -> DRAW
* ex3: paperChoice(SCISSORS) -> PLAYER2_WINS
* ex4: paperChoice(0) -> ERROR
* ex5: paperChoice(-1) -> ERROR
* ex6: paperChoice(4) -> ERROR
*
* *** ADD METHOD CODE HERE ***
*/
/**
* Lab 9.7
*
* scissorsChoice(int) -> int
*
* method consumes the computer player's choice (ROCK, PAPER or SCISSORS),
* assuming the human player has chosen SCISSORS
* method produces game outcome (PLAYER1_WINS, PLAYER2_WINS, or DRAW)
*
* ex1: scissorsChoice(ROCK) -> PLAYER2_WINS
* ex2: scissorsChoice(PAPER) -> PLAYER1_WINS
* ex3: scissorsChoice(SCISSORS) -> DRAW
* ex4: scissorsChoice(0) -> ERROR
* ex5: scissorsChoice(-1) -> ERROR
* ex6: scissorsChoice(4) -> ERROR
*
* *** ADD METHOD CODE HERE ***
*/
} // end class labIn: Computer Science