IN C++: Using a single for loop, output the even numbers between 2 and 1004 (inclusive) that iterates (loops) exactly 502 times. The outputted numbers be aligned in a table with 10 numbers per row. Each column in the table should be 5 characters wide. Do not nest a loop inside of another loop.
In: Computer Science
List and describe the parts of the feasibility assessment portion of a baseline project report.
In: Computer Science
Explain how corporations have adopted the Ecommerce as part of the strategy to expand its operations over new customers or new geographic areas.
In: Computer Science
Extend the Hello Goodbye application from the class to include the following using android studio:
1. Add a Text Color button underneath the existing Exclamation button, using the same text color and background image. When this button is clicked, toggle the display color for the Hello or Goodbye text between the original color and the color Red.
2. Add a Reset button underneath the new text color button, using the same text color and background image. When this button is clicked, return the text display to “Hello” in the original color.
activity main XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="@drawable/background">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/hello"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textColor="@color/dusty_rose"
android:textSize="60sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:src="@drawable/greetimage"
android:contentDescription="@string/exclaim_img" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/exclaim_btn"
android:layout_below="@+id/imageView"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:background="@drawable/exclamationbtn" />
<Button
android:id="@+id/button2"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView"
android:layout_centerHorizontal="true"
android:layout_marginTop="102dp"
android:background="@drawable/exclamationbtn"
android:text="text color" />
</RelativeLayout>
Main activity.java
package com.cornez.hellogoodbye;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
//DECLARE OBJECTS TO INTERFACE WITH LAYOUT COMPONENTS
Button exclaimBtn;
Button textcolBtn;
private TextView greetingTextView;
//INDICATES HELLO IS CURRENTLY DISPLAYED
private boolean isHello;
@Override
protected void onCreate(Bundle savedInstanceState) {
//TASK 1: INFLATE THE MAIN SCREEN LAYOUT USED BY THE APP
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//TASK 2: ESTABLISH REFERENCES TO THE TEXTVIEW AND BUTTON
Button exclaimBtn = (Button) findViewById(R.id.button1);
Button textcolBtn = (Button) findViewById(R.id.button2);
greetingTextView = (TextView) findViewById(R.id.textView);
//TASK 3: INITIALIZE GREETINGS
initializeGreeting();
//TASK 4: REGISTER THE LISTENER EVENT FOR THE BUTTON
exclaimBtn.setOnClickListener(toggleGreeting);
}
private final View.OnClickListener toggleGreeting =
new View.OnClickListener() {
public void onClick(View btn) {
//TASK: CONSTRUCT THE TOGGLE GREETING
if (isHello) {
isHello = false;
greetingTextView.setText(R.string.goodbye);
} else {
isHello = true;
greetingTextView.setText(R.string.hello);
}
}
};
int conditionColor;
private void initializeGreeting() {
isHello = true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu;
// this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}In: Computer Science
This is the Painting.javasource file for you to modify (bluelines are my additions):
public class Painting
{
public static void main(String[] args)
{
double width, length, wallArea, ceilingArea;
final double HEIGHT = 8;
System.out.println("Calculation of Paint Requirements");
System.out.print("Enter room length: ");
length = Keyboard.nextDouble();
// these 2 lines will make a nice function, promptDouble,
// then replace those 2 lines with this single line:
// length = promptDouble("Enter room length: ");
System.out.print("Enter room width: ");
width = Keyboard.nextDouble();
// these 2 lines should be replaced in the same way:
// width = promptDouble("Enter room width: ");
wallArea = 2 * (length + width) * HEIGHT; // ignore doors
// this line should use a perimeterfunction instead, as in:
// wallArea = perimeter(length, width) * HEIGHT;
ceilingArea = length * width;
// this line should use a new function called area,
// similar to perimeter, like so:
// ceilingArea = area(length, width);
System.out.println("The wall area is " + wallArea +
" square feet.");
System.out.println("The ceiling area is " + ceilingArea +
" square feet.");
}
}
Your job in this Lab is to write these three functions and make the above changesin the Java program Painting.java.
In: Computer Science
Object Design Example: Bank Account Object
Implement the bank account class that stores account number and the balance. It has methods to deposit and withdraw money. In addition, the default constructor sets account number to 0000 and balance 0. Other constructor should take the account number and the initial balance as parameters. Finally, the account class should have a static data member that stores how many accounts are created for a given application.
a) Draw the UML diagram
b) Write Java code to implement the bank account class
In: Computer Science
C++ PLEASE
IMPORTANT:
This program will store roster and rating information for a basketball team. Coaches rate players during tryouts to ensure a balanced team. A roster can include at most 10 players.
(1) Prompt the user to input five pairs of numbers: A player's
jersey number (0 - 99) and the player's rating (1 - 9). Store the
jersey numbers in one int array and the ratings in another int
array. Output these arrays (i.e., output the roster).
Ex:
Enter player 1's jersey number: 84 Enter player 1's rating: 7 Enter player 2's jersey number: 23 Enter player 2's rating: 4 Enter player 3's jersey number: 4 Enter player 3's rating: 5 Enter player 4's jersey number: 30 Enter player 4's rating: 2 Enter player 5's jersey number: 66 Enter player 5's rating: 9 ROSTER Player 1 -- Jersey number: 84, Rating: 7 Player 2 -- Jersey number: 23, Rating: 4 ...
(2) Implement a menu of options for a user to modify the roster.
Each option is represented by a single character. The program
initially outputs the menu, and outputs the menu after a user
chooses an option. The program ends when the user chooses the
option to Quit.
Ex:
MENU a - Add player d - Remove player u - Update player rating r - Output players above a rating o - Output roster q - Quit Choose an option:
(3) Implement the "Output roster" menu option.
Ex:
ROSTER Player 1 -- Jersey number: 84, Rating: 7 Player 2 -- Jersey number: 23, Rating: 4 ...
(4) Implement the "Add player" menu option. If the user chooses this option and the roster is full, print the following error message:
Impossible to add new player: roster is full.
If the roster is not full, prompt the user for a new player's
jersey number and rating, and append the values to the two
arrays.
Ex:
Enter a new player's jersey number: 49 Enter the player's rating: 8
(5) Implement the "Delete player" menu option. If the user chooses the option when the roster is empty, immediately print the message:
Can not delete from empty roster.
If the roster is not empty, prompt the user for a player's
jersey number. Remove the player from the roster (delete the jersey
number and rating), paying attention not to leave unused spaces in
the two arrays.
Ex:
Enter a jersey number: 4
If the given jersey number is not found, inform the user:
Error! Player not found.
(6) Implement the "Update player rating" menu option. Prompt the
user for a player's jersey number. Prompt again for a new rating
for the player, and then look up and change that player's
rating.
Ex:
Enter a jersey number: 23 Enter a new rating for player: 6
In this case, if the given jersey number is not found, no further action is taken (note that the format of the program requires both input either way).
(7) Implement the "Output players above a rating" menu option.
Prompt the user for a rating. Print the jersey number and rating
for all players with ratings above the entered value.
Ex:
Enter a rating: 5 ABOVE 5 Player 1 -- Jersey number: 84, Rating: 7 ...
If no players are found above a given rating, the program will simply produce an empty list.
BONUS
For an extra 10 points, implement a secret option s that prints the message:
Executing secret option!
and sorts the roster by jersey number. Do not add this option to the MENU message. And remember to move the player rating accordingly!
In: Computer Science
Code programs using ReadlineSync for prompts.
Note: For all programs, create and call a main function, and if required additional functions called by the main. Also please use the ES6 style of keywords => instead of the older function and for local scope variables use the keyword let, not var
Name: cookout.js
Assume that hot dogs come in packages of 10, and hot dog buns come in packages of 8. Write a program called cookout.js, that calculates the number of packages of hot dogs and the number of packages of hot dog buns needed for a cookout, with the minimum amount of leftovers.
The program will prompt for the number of people attending the cookout and as how many hot dogs each guest will eat. The program should display the following details.
The minimum number of packages of hot dogs required.
The minimum number of packages of hot dog buns required.
The number of hot dogs that will be left over.
The number of hot dog buns that will be left over.
In: Computer Science
Code programs using ReadlineSync for prompts.
Note: For all programs, create and call a main function, and if required additional functions called by the main. Also please use the ES6 style of keywords => instead of the older function and for local scope variables use the keyword let, not var
Name: coinflip.js
For this program you will have two functions, one called main and the second called flip. This program is also required the use of a loop construct.
Write a program that simulates tossing a coin. Prompt the user for how many times to toss the coin. Code a function called flip with no parameters that randomly ( use the math library random ) returns either the String "heads"or the string "tails". Call this function in main as many times as requested using a loop and report the results. See Example outputs below.
Example Outputs
How many times should I toss the coin? 1000
Results of 1000 tosses.
Heads: 483, tails: 517
How many times should I toss the coin? 1000000
Results of 1000000 tosses.
Heads: 500074, tails: 499926
Recheck the requirements before you submit.
In: Computer Science
Code programs using ReadlineSync for prompts.
Note: For all programs, create and call a main function, and if required additional functions called by the main. Also please use the ES6 style of keywords => instead of the older function and for local scope variables use the keyword let, not var
triangle.js
Write a program that is required to use nested loops to generate a triangle as shown in the sample run below. The program should begin by prompting the user to enter the number of lines in the triangle and output to the console to match the example below.
Hint: Each line will contain either "O" or " " (spaces) to align the output to appear right justified
How many lines of the triangle?:6
OOOOOO
OOOOO
OOOO
OOO
OO
O
In: Computer Science
How to do this program in C ? You have a sock drawer. You have an infinite supply of red, green, yellow, orange, and blue socks. 1) Choose how many socks of each color you will put into the drawer. 0 is an ok number, but it would be nonsense to allow the user to put a negative number of socks into the drawer, so if the user tries to do that, print an error message and quit the program. 2) Ask the user to specify two colors of socks typing the first letters of the two colors in response to a prompt. Sample dialog: What two colors of socks are you interested in:YO It is an error to specify the same color twice. Your response of YO would mean that you are interested in yellow and orange socks. RR would be an improper response and should recieve an error message. 3) Pretend that the user shuts their eyes, reaches into the drawer, and retrieves one sock. Calculate the probability that the sock is one of the two specified colors. If c1 and c2 are the specified colors, and nk is the number of socks of color k, then the required probability would be (n1 + n2) / (n1 + n2 + n3 + n4 + n5) For instance, suppose there are 5 red socks, 4 green socks, 3 yellow socks, 2 ornage socks and 1 blue sock. If the user specified red and yellow (RY) the probability would be (5 + 3) / (5 + 4 + 3 + 2 + 1) Use ints to hold the number of socks of each color, but calculate the probabilities as doubles.
In: Computer Science
Programming Assignment 1 Performance Assessment
Objective:
To write a C program (not C++) that calculates the average CPI, total processing time (T), and MIPS of a sequence of instructions, given the number of instruction classes, the CPI and total count of each instruction type, and the clock rate (frequency) of the machine.
The following is what the program would look like if it were run interactively. Your program will read values without using prompts.
Inputs:
• Clock rate of machine (MHz) • Number of instruction classes (types) • CPI of each type of instruction • Total instruction count for each type of instruction
Specification:
The program calculates the output based on choosing from a menu of choices, where each choice calls the appropriate procedure, where the choices are:
1) Enter parameters 2) Print Results 3) Quit
“Print Results” Output Format:
The Print Results option prints out the following information as shown below. Finally use upper case letters and tabs so that your inputs and outputs look just like the example.
FREQUENCY (MHz) input value
INSTRUCTION DISTRIBUTION
CLASS CPI COUNT input value input value input value input value input value input value input value input value input value
PERFORMANCE VALUES
AVERAGE CPI computed value TIME (ms) computed value MIPS computed value
Test Run:
An example of what a test run should look like when run on a terminal on Linux is shown below. All labels should be in CAPS (as shown in the example) and blank lines between input prompts and output lines should be used as in the example.
$ ./aout
(Program Execution Begin)
1) Enter Parameters 2) Print Results 3) Quit
Enter Selection: 1
Enter the frequency of the machine (MHz): 200
Enter the number of instruction classes: 3
Enter CPI of class 1: 2 Enter instruction count of class 1 (millions): 3
Enter CPI of class 2: 4 Enter instruction count of class 2 (millions): 5
Enter CPI of class 3: 6 Enter instruction count of class 3 (millions): 7
Performance assessment:
1) Enter Parameters 2) Print Results 3) Quit
Enter Selection: 2
FREQUENCY (MHz): 200
INSTRUCTION DISTRIBUTION
CLASS CPI COUNT
1 2 3
2 4 5
3 6 7
PERFORMANCE VALUES
AVERAGE CPI 4.53
TIME (ms) 340.00
MIPS 44.12
Dr. George Lazik (display your full name, not mine)
Performance assessment:
1) Enter Parameters 2) Print Results 3) Quit
Enter selection: 3
Program Terminated Normally
Notes:
Make sure all calculations are displayed truncated to 2 decimal fractional places, using the format “%.2f” in the printf statements.
Be sure that execution time is measured in milliseconds (ms).
To typecast an int x to a float y, use y = (float)x or simply y = 1.0*x
To create proper spacing, use “\t” to tab and “\n” for a new line.
Your Submission to the zyLab:
The source code as a single file named: assignment_1.c, submitted to the zyLab for Assignment 1. It will be graded when you do. You can submit your solution up to 3 times and the best score will be recorded.
You can use any editor and/or compiler you wish, but make sure your code compiles and executes under the gcc compiler on the zyLab; otherwise you will receive 0 points.
Sample Test Bench Run on a zyLab. Note that all input prompts have been eliminated from this version.
The input values:
1 200 3 2 3 4 5 6 7 2 3
The outputs:
Note that spacing is irregular due to publishing quirks here. Use TABS for spacing and you will get correct results.
FREQUENCY (MHz): 200
INSTRUCTION DISTRIBUTION
CLASS CPI COUNT
1 2 3
2 4 5
3 6 7
PERFORMANCE VALUES
AVERAGE CPI 4.53
TIME (ms) 340.00
MIPS 44.12
PROGRAM TERMINATED NORMALLY
Assignment 1 Skeleton
#include <stdio.h>
#include <stdlib.h>
//initialize values
//
int * cpi_i; //define cpi_i as a pointer to one of more
integers
//
// procedure to read all input parameters
//
void enter_params()
{
//initialize counter variables
//
int i;
cpi_sum=0;
instr_total=0;
scanf("%d", &mhz);// input frequency
scanf("%d",&classes);// input number of instruction classes
cpi_i = (int *)malloc(classes*sizeof(int)); //dynamically
allocate an array
count_i = (int *)malloc(classes*sizeof(int));//dynamically allocate
a second array
instr_total =0;
for (i=1; i <= classes; i++)
{
scanf("%d", &cpi_i[i]);// input
instruction's cpi
scanf("%d", &count_i[i]);//
input instruction's count
instr_total += count_i[i];
cpi_sum = cpi_sum + (cpi_i[i] *
count_i[i]);
}
printf("\n");
return;
}
//function computes average cpi
//
float calc_CPI()
{
}
//function computes execution time
//
float calc_CPU_time()
{
}
//function computes mips
//
float calc_MIPS()
{
}
//procedure prints input values that were read
//
void print_params()
{
}
//procedure prints calculated values
//
void print_performance()
{
}
//main program keeps reading menu selection and dispatches
accordingly
//
int main()
{
void fee(cpi_i);//free up space previously allocated above
return 0;
}
In: Computer Science
In: Computer Science
How many times will an "X" appear in the following nested
loop?
for (outer = 0; outer <=5; outer++)
{for (inner = 1; inner <=4; inner+1)
{cout<<("X");}
}
|
9 |
|
|
10 |
|
|
20 |
|
|
24 |
|
|
none of the above |
In: Computer Science
1. create a class called ArrayStack that is a generic class. Create a main program to read in one input file and print out the file in reverse order by pushing each item on the stack and popping each item off to print it. The two input files are: tinyTale.txt and numbers.txt. Rules: You cannot inherit the StackofStrings class.
2. Using your new ArrayStack, create a new class called RArrayStack. To do this, you need
a) remove the capacity parameter from the constructor and create the array with 8 as the starting size
b) create a new method called resize that takes a parameter (capacity)
c) change push() to check for length of array. If it is at the limit then call resize to increase it to twice the size Use the same main program from 1 and the two input files to test out your program. RULE: You cannot use ArrayList – you must use a primitive Java arrays.
import java.util.Iterator;
import java.util.NoSuchElementException;
public class StackOfStrings implements
Iterable<String> {
private String[] a; // holds the items
private int N; // number of items in stack
// create an empty stack with given capacity
public StackOfStrings(int capacity) {
a = new String[capacity];
N = 0;
}
public boolean isEmpty() {
return N == 0;
}
public boolean isFull() {
return N == a.length;
}
public void push(String item) {
a[N++] = item;
}
public String pop() {
return a[--N];
}
public String peek() {
return a[N-1];
}
public Iterator<String> iterator() {
return new ReverseArrayIterator();
}
public class ReverseArrayIterator implements
Iterator<String> {
private int i = N-1;
public boolean hasNext() {
return i >= 0;
}
public String next() {
if (!hasNext()) throw new NoSuchElementException();
return a[i--];
}
public void remove() {
throw new UnsupportedOperationException();
}
}
}
Numbers.txt
20
7
99
88
1
2
3
4
30
16
19
50
55
60
61
6
68
28
32
--------------------------------------------------------------
tinyTale.txt
it was the best of times it was the worst of times
it was the age of wisdom it was the age of foolishness
it was the epoch of belief it was the epoch of incredulity
it was the season of light it was the season of darkness
it was the spring of hope it was the winter of despair
In: Computer Science