By using examples differentiate between a single‐alternative and a dual‐ alternative if statement. 8 marks
In: Computer Science
Write a Python program that creates a class which represents a Student Grade. The class includes a function that reads a text file called Course_Score.txt. A sample of the file is provided below. Each row in the file corresponds to the Last Name, First Name, ClassWork score (100), Mid-Term score (100), and Final-Exam score (100). Also include the the following functions to process the content read from the file. a. getData(): This method reads the data from a file and stores the data as a list. b. grade(): This method calculates total score, percentage and grade for each student. A grade (above 90%), B grade (above 80%), C grade (above 60%), D grade (above 50%), and F grade (below 50%) c. highestTotal() and lowestTotal(): These methods calculate highest and lowest total scores in class.
Sample input file: Course_Score.txt
Naji Hasan 90 85 87
Lisa Smith 80 67 70
Andy Malik 75 80 52
Ravi Gupta 90 95 98
Dave Blair 50 61 70
Sara Clark 70 65 81
Sami Moosa 55 50 71
Imed Radhi 90 83 89
Kira Sunny 65 70 69
Hind Ahmed 70 81 88
In: Computer Science
Construct an HTML page that contains a three-level nesting list (you may choose the type of the list you want to use). One item on each level. Use the three attached images as the content of each of the three list items.
-exam prep
-msnlink
-success
example for person who asked in comments
LeBron James Sr. is an American professional basketball player for the Los Angeles Lakers of the National Basketball Association. He is widely considered to be one of the greatest basketball players in NBA history.
Anthony Davis Jr. is an American professional basketball player for the Los Angeles Lakers of the National Basketball Association. He plays the power forward and center positions. Davis was the first overall pick in the 2012 NBA draft.
Jayson Christopher Tatum is an American professional basketball player for the Boston Celtics of the National Basketball Association (NBA).
Gordon Daniel Hayward is an American professional basketball player for the Boston Celtics of the National Basketball Association. He played two seasons of college basketball for Butler University.
In: Computer Science
In: Computer Science
In: Computer Science
1. Given the following values, evaluate the logical value of each expression. [3 each]
int a = 3;
int b = 8;
int c = 3;
int d = 10;
a. b < c && c < d
b. !(a == c && c != d)
c. !(d <= b) || (c > a)
d. a == c || c == d
2. Given the following values, evaluate the logical value of each expression. [4 each]
int g = 6;
int h = 8;
int i = 6;
int j = 15;
a. (i == g || g < i) || j == h
b. h > j || g != i && i != h
Bonus. How would the logical test of a ≤ b ≤ c be written in C++? [1]
In: Computer Science
PYTHON
Write a regular expression that will accept any properly formatted email address, and reject any invalid email address. An example of a valid inputted email address would be "[email protected]".
In: Computer Science
It is a strict requirement that this code is implemented in python. The code must be implemented from scratch not using e.g. numpy etc.
a. Create a function that takes a matrix X of all sizea as input and gives the transposed matrix as output. Example
transposeMatrix([[1,2]
,[3,4]
,[5,6]]) = [[1,3,5]
,[2,4,6]]
b. Create a function that multilpies a matrix X1 and X2 of all sizes. Example
x1 = [[0,1]
,[1,0]
]
x2 = [[1, 0]
,[0,-1]
]
matrtixMultl(x1,x2) = [[0, -1]
,[1, 0]
]
c. Create a function that takes a square matrix as input and creates its inverse matrix as output. And that is such that matrixMult(A,matrixInvert(A)) is the unit matrix
In: Computer Science
IN C++
Create a class called TextInt. The purpose of a TextInt is to store an integer and convert it to the English text form of the integer when needed, such as ‘zero’ for 0, ‘one’ for 1, and so on, up to ‘nine thousand nine hundred ninety nine’ for 9999. You do NOT need punctuation (commas, hyphens, ‘and’, etc.) The TextInt class should have its own .h and .cpp files. At least the translate function should be implemented in the .cpp file. The rest can be inline functions. A TextInt should have a private member variable number of type int. The TextInt class should have static string members to help translate integers to text. For example, to represent the unique words for translating, you would use:
static string lessThan20[] = {“zero”, “one”, …, “eighteen”, “nineteen”};
static string tens[] = {“twenty”, “thirty”, … static string hundred = “Hundred”;
Any number can be translated using a combination of these, such as 1234 = 1000 + 200 + 30 + 4 = one thousand two hundred thirty four.
The class should have a default constructor with one parameter that initializes the value of the member variable number. Note that the parameter must have a default value to make it a default constructor. It should have public methods (member functions) to return the integer and text versions of number, and to change the value of number.
Overload the following operators so that TextInt can work just like a normal int in code: +, -, /, *, %, and <<.
Note that the first 5 will be almost identical.
For example, this code should work when you are done:
TextInt textInt1(2458), textInt2(1278);
TextInt textInt3 = textInt1 + textInt2;
cout << textInt3 << endl;
Should output: 3736: three thousand seven hundred thirty six
In: Computer Science
In this assignment we are not allowed to make changes to Graph.h it cannot be changed! I need help with the Graph.cpp and the Driver.cpp.
Your assignment is to implement a sparse adjacency matrix data structure Graph that is defined in the header file Graph.h. The Graph class provides two iterators. One iterator produces the neighbors for a given vertex. The second iterator produces each edge of the graph once.
Additionally, you must implement a test program that fully exercises your implementation of the Graph member functions. Place this program in the main() function in a file named Driver.cpp.
The purpose of an iterator is to provide programmers a uniform way to iterate through all items of a data structure using a forloop. For example, using the Graph class, we can iterate thru the neighbors of vertex 4 using:
Graph::NbIterator nit ; for (nit = G.nbBegin(4); nit != G.nbEnd(4) ; nit++) { cout << *nit << " " ; } cout << endl ;
The idea is that nit (for neighbor iterator) starts at the beginning of the data for vertex 4 in nz and is advanced to the next neighbor by the ++ operator. The for loop continues as long as we have not reached the end of the data for vertex 4. We check this by comparing against a special iterator for the end, nbEnd(4). This requires the NbIterator class to implement the ++, !=and * (dereference) operators.
Similarly, the Graph class allows us to iterate through all edges of a graph using a for loop like:
Graph::EgIterator eit ; tuple<int,int,int> edge ; for (eit = G.egBegin() ; eit != G.egEnd() ; eit++) { edge = *eit ; // get current edge cout << "(" << get<0>(edge) << ", " << get<1>(edge) << ", " << get<2>(edge) << ") " ; } cout << endl ;
Note that each edge should be printed only once, even though it is represented twice in the sparse adjacency matrix data structure.
Since a program may use many data structures and each data structure might provide one or more iterators, it is common to make the iterator class for a data structure an inner class. Thus, in the code fragments above, nit and eit are declared asGraph::NbIterator and Graph::EgIterator objects, not just NbIterator and EgIterator objects.
Here are the specifics of the assignment, including a description for what each member function must accomplish.
Requirement: your implementation must dynamically resize the m_nz and m_ci arrays. See the descriptions of Graph(constructor) and addEdge, below.
Requirement: other than the templated tuple class, you must not use any classes from the Standard Template Library or other sources, including vector and list. All of the data structure must be implemented by your own code.
Requirement: your code must compile with the original Graph.h header file. You are not allowed to make any changes to this file. Yes, this prevents you from having useful helper functions. This is a deliberate limitation of this project. You may have to duplicate some code.
Requirement: a program fragment with a for loop that uses your NbIterator must have worst case running time that is proportional to the number of neighbors of the given vertex.
Requirement: a program fragment with a for loop that uses your EgIterator must have worst case running time that is proportional to the number of vertices in the graph plus the number of edges in the graph.
Graph.h:
#ifndef _GRAPH_H_
#define _GRAPH_H_
#include <stdexcept> // for throwing out_of_range exceptions
#include <tuple> // for tuple template
class Graph {
public:
// Graph constructor; must give number of vertices
Graph(int n);
// Graph copy constructor
Graph(const Graph& G);
// Graph destructor
~Graph();
// Graph assignment operator
const Graph& operator= (const Graph& rhs);
// return number of vertices
int numVert();
// return number of edges
int numEdge();
// add edge between u and v with weight x
void addEdge(int u, int v, int x);
// print out data structure for debugging
void dump();
// Edge Iterator inner class
class EgIterator {
public:
// Edge Iterator constructor; indx can be used to
// set m_indx for begin and end iterators.
EgIterator(Graph *Gptr = nullptr, int indx = 0);
// Compare iterators; only makes sense to compare with
// end iterator
bool operator!= (const EgIterator& rhs);
// Move iterator to next printable edge
void operator++(int dummy); // post increment
// return edge at iterator location
std::tuple<int,int,int> operator*();
private:
Graph *m_Gptr; // pointer to associated Graph
int m_indx; // index of current edge in m_nz
int m_row; // corresponding row of m_nz[m_indx]
};
// Make an initial edge Iterator
EgIterator egBegin();
// Make an end iterator for edge iterator
EgIterator egEnd();
// Neighbor Iterator inner class
class NbIterator {
public:
// Constructor for iterator for vertices adjacent to vertex v;
// indx can be used to set m_indx for begin and end iterators
NbIterator(Graph *Gptr = nullptr, int v = 0, int indx = 0);
// Compare iterators; only makes sense to compare with
// end iterator
bool operator!=(const NbIterator& rhs);
// Move iterator to next neighbor
void operator++(int dummy);
// Return neighbor at current iterator position
int operator*();
private:
Graph *m_Gptr; // pointer to the associated Graph
int m_row; // row (source) for which to find neighbors
int m_indx; // current index into m_nz of Graph
};
// Make an initial neighbor iterator
NbIterator nbBegin(int v);
// Make an end neighbor iterator
NbIterator nbEnd(int v);
private:
int *m_nz; // non-zero elements array
int *m_re; // row extent array
int *m_ci; // column index array
int m_cap; // capacity of m_nz and m_ci
int m_numVert; // number of vertices
int m_numEdge; // number of edges
};
#endifIn: Computer Science
Part 1
Recall from Chapter 1 that computer memory is comprised of individual bits of data. A bit (short for binary digit) can store one of only two values, commonly referred to as 0 and 1. However, using two bits, you can represent four different values through the bit patterns 00, 01, 10, and 11. With three bits, you can represent eight different values—via 000, 001, 010, 011, 100, 101, 110, and 111. In general, N bits of memory enable you to represent 2N different values.
Create a Web page named bits.html that contains a text box where the user can enter a number, call it N. At the click of a button, your page should compute and display 2N, the number of values that can be represented using the specified quantity of bits. For example, if the user entered 10 in the text box, the page would display the message:
With 10 bits, you can represent 1024 different values.
Once you have created your page, use it to determine the number of values that each of the following can represent (Test the following numbers to see if they give the correct results)
8 bits (1 byte)
16 bits (2 byte)
32 bits (4 bytes)
64 bits (8 bytes)
Part 2
Most lotteries select winning numbers by drawing numbered balls out of bins. For example, a typical Pick-4 lottery will utilize four bins, each containing balls with numbers starting at 0. If there are 10 balls to choose from in each of four bins, labeled 0 to 9, then 104 = 10,000 different number sequences can potentially be picked. Increasing the number of balls significantly increases the number of possible sequences, which significantly decreases a person’s odds of winning. For example, if there are 20 balls to choose from in each bin, labeled from 0 to 19, then 204 = 160,000 different number sequences could be selected.
Make a copy of the lucky1.html page from Figure 7.4 in your text and name it pick4.html. Then modify this new page so that it simulates a Pick-4 lottery. Your page should have one text box, where the user can enter the highest ball number (it is assumed that the lowest ball number is always 0). When a button is clicked, four random ball numbers should be selected and displayed in a message such as the following:
The Pick-4 winners are: 5-0-8-2
Part 3
Modify your pick4.html page from above so that it makes use of a function in the HEAD. Your function should contain the code previously assigned to the button, and have a name descriptive of the task it performs, such as GeneratePicks or PickNumbers. You should then modify the button’s ONCLICK attribute to call that function.
In: Computer Science
Allow the user to enter the number of people in the party. Calculate and display the amount owed by each person if the bill were to be split evenly among the party members.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mdc.tippcalcula">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
-------------------------------
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2"
android:useDefaultMargins="true"
tools:context=".MainActivity">
<EditText
android:id="@+id/amountEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint=""
android:digits="0123456789"
android:inputType="number"
android:layout_column="0"
android:layout_columnSpan="2"
android:maxLength="6"/>
<TextView
android:id="@+id/amountTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="0"
android:layout_columnSpan="2"
android:layout_gravity="fill_horizontal"
android:background="@color/amount_background"
android:elevation="@dimen/elevation"
android:hint="@string/enter_amount"
android:padding="@dimen/textview_padding"
/>
<TextView
android:id="@+id/percentTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:text="@string/tip_percentage" />
<SeekBar
android:id="@+id/percentSeekBar"
android:layout_width="wrap_content"
android:layout_height="@dimen/seekbar_height"
android:layout_gravity="fill_horizontal"
android:max="30"
android:progress="15"/>
<TextView
android:id="@+id/TipLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="@string/tip" />
<TextView
android:id="@+id/tipTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:background="@color/result_background"
android:elevation="@dimen/elevation"
android:gravity="center"
android:padding="@dimen/textview_padding" />
<TextView
android:id="@+id/totalLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="@string/total" />
<TextView
android:id="@+id/totalTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:background="@color/result_background"
android:elevation="@dimen/elevation"
android:gravity="center"
android:padding="@dimen/textview_padding"
/>
<EditText
android:id="@+id/numberOfPeopleEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:background="@color/result_background"
android:elevation="@dimen/elevation"
android:gravity="center"
android:padding="@dimen/textview_padding"
android:ems="10"
android:hint="Enter Number Of People"
android:digits="012345678"
android:inputType="number"
android:layout_columnSpan="2"/>
<TextView
android:id="@+id/eachPersonLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="@string/each" />
<TextView
android:id="@+id/eachPersonTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:background="@color/result_background"
android:elevation="@dimen/elevation"
android:gravity="center"
android:padding="@dimen/textview_padding"
/>
</GridLayout>
----------
package com.mdc.tippcalcula;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import java.text.NumberFormat;
public class MainActivity extends AppCompatActivity {
private static final NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
private static final NumberFormat percentFormat = NumberFormat.getCurrencyInstance();
private double billAmount = 0.0;
private double percent = 0.15;
private double numPeople = 0;
private TextView percentTextView;
private TextView tipTextView;
private TextView amountTextView;
private TextView totalTextView;
private TextView eachPersonTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
amountTextView = (TextView) findViewById (R.id.amountTextView);
percentTextView = (TextView) findViewById (R.id.percentTextView);
tipTextView = (TextView) findViewById(R.id.tipTextView);
totalTextView = (TextView) findViewById(R.id.totalTextView);
eachPersonTextView = (TextView) findViewById(R.id.eachPersonTextView);
tipTextView.setText(currencyFormat.format(0));
totalTextView.setText(currencyFormat.format(0));
eachPersonTextView.setText(currencyFormat.format(0));
EditText amountEditText = (EditText) findViewById(R.id.amountEditText);
amountEditText.addTextChangedListener(amountEditTextWatcher);
SeekBar percentSeekBar = (SeekBar) findViewById(R.id.percentSeekBar);
percentSeekBar.setOnSeekBarChangeListener(seekBarListener);
}
private void calculate(){
percentTextView.setText(percentFormat.format(percent));
double tip = billAmount * percent;
double total = billAmount + tip;
tipTextView.setText(currencyFormat.format(tip));
totalTextView.setText((currencyFormat.format(total)));
}
private final OnSeekBarChangeListener seekBarListener = new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean b)
{
percent = progress / 100.0;
calculate();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
};
private final TextWatcher amountEditTextWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)
{
try {
billAmount = Double.parseDouble(charSequence.toString()) / 100.0;
amountTextView.setText(currencyFormat.format(billAmount));
}
catch (NumberFormatException e){
amountTextView.setText("");
billAmount = 0.0;
}
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { }
@Override
public void afterTextChanged(Editable editable) { }
};
}
------
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="textview_padding">12dp</dimen>
<dimen name="elevation">4dp</dimen>
<dimen name="seekbar_height">40dp</dimen>
</resources>
---
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#6200EE</color>
<color name="colorPrimaryDark">#3700B3</color>
<color name="colorAccent">#03DAC5</color>
<color name="amount_background">#BBDEFB</color>
<color name="result_background">#ffE0B2</color>
</resources>
----
<resources>
<string name="app_name">Tip Calculator</string>
<string name="enter_amount"> Enter Amount</string>
<string name="tip_percentage">15%</string>
<string name="tip">Tip</string>
<string name="total">Total</string>
<string name="number">No. Of People</string>
<string name="each">Each Person</string>
</resources>In: Computer Science
Java Programming Question:
A dog shelter would like a simple system to keep track of all the dogs that pass through the facility. The system must record for each dog:
dogId (int) - must be unique
name (string)
age (double) - cannot be less than 0 or more than 25
breed (string)
sex (char) – m for male, f for female
foundHome (bool) - true means the dogs has been places in a home false otherwise.
You must create an object oriented java solution with a text based menu as summarized on the next page. The system must check that valid data is entered. For example, the menu has four items so only 1 to 5 must be allowed as input from the menu.
Summary of Operations
System Menu:
Overview:
Add Dog:
When a dog is added to the system, you must check that the dogId is not already used in the system. All new dogs have no home as yet (foundHome = false).
View all Dogs:
This menu option shows all dogs in the system. This includes dogs that have a home and those that do not.
View all available dogs:
Shows all dogs in the system, that have no homes as yet.
View dog:
Asks the user for a dogId and then displays the dog information if found and “There is no dog with that id..” if it is not found.
Update dog home status:
Asks the user for a dogId. If a dog with that id is found, the “foundHome” status is changed to true and the dog information is to be displayed. If the dog is not found the message “There is no dog with that id..” should be displayed.
In: Computer Science
In: Computer Science
Python:
Write a program that keeps track of a game score and declares the winner when the game is over. A game is over when either one player scores 10 or more points with at least 2 more points than the opponent. A game is also over when one player scores 7 points and the opponent scores none. The program should begin by asking the names of the two players. Then, it should keep asking who won the point till the game is over (you will need to prompt user to determine who won the point. In the end it should display the winner and the final score.
In: Computer Science