Code1:
#include
int main(){
int res1, res2, res;
printf("\nEnter Value of Each Resistance 1: ");
scanf("%d", &res1);
printf("\nEnter Value of Each Resistance 2: ");
scanf("%d", &res2);
res = res1+res2;
printf("\nEquivalent Series Resistance : %d Kohm\n",
res);
return (0);
}
----------------------------------------------------------------------------------------------------------
Code2:
#include
int main(){
int res1, res2, res;
printf("\nEnter Value of Each Resistance 1: ");
scanf("%d", &res1);
printf("\nEnter Value of Each Resistance 2: ");
scanf("%d", &res2);
res = (res1*res2)/(res1+res2);
printf("\nEquivalent Parellel Resistance : %d Kohm\n",
res);
return (0);
}
Take the two programs and combine them into a single program(using c not c++) that uses an if and else statement to calculate R total either in series or parallel based on the users preference (ask the users which way they want the resistance calculated).
In: Computer Science
(C++) Write a function that takes as an input parameter an integer that will represent the length of the array and a second integer that represents the range of numbers the random number should generate (in other words, if the number is 50, the random number generator should generate numbers between 0 and 49 including 49. The function then sorts the list by traversing the list, locating the smallest number, and printing out that smallest number, then replacing that number in the array with the second parameter +1 (so in our above example, it would be 51. ) Continue to do this until every number in the original array is printed out in order
In: Computer Science
Using Bash script,
1. Print the multiplication table upto 10 rows. Ask the user to enter a number. say user enters 10, your output should be :
[srivatss@athena shell]> ./mult.sh
I will be printing the multiplication table
Please enter a number
10
1 x 10 = 10
2 x 10 = 20
3 x 10 = 30
4 x 10 = 40
5 x 10 = 50
6 x 10 = 60
7 x 10 = 70
8 x 10 = 80
9 x 10 = 90
10 x 10 = 100
[ 5 points ]
2. Create a Simple Calculator [ 20 points , 5 points for each operator]
Ask the user for the first operand, second operand and the operator. You output the result to the user based on the operator. Here is the sample output
[srivatss@athena shell]> ./calc.sh
Welcome to my Simple calculator
Please enter the first operand
2
Please enter the second operand
3
Please enter the operator
+
2 + 3 = 5
[srivatss@athena shell]> ./calc.sh
Welcome to my calculator
Please enter the first operand
4
Please enter the second operand
2
Please enter the operator
-
4 - 2 = 2
[srivatss@athena shell]> ./calc.sh
Welcome to my calculator
Please enter the first operand
4
Please enter the second operand
5
Please enter the operator
*
4 * 5 = 20
[srivatss@athena shell]> ./calc.sh
Welcome to my calculator
Please enter the first operand
6
Please enter the second operand
3
Please enter the operator
/
6 / 3 = 2
3. Using RANDOM function and touch command , create a file with prefix =BatchJob followed by the random number.
For instance, I ran my script, it created a file with random number 10598.
[srivatss@athena shell]> ./cmds.sh
BatchJob10598
[ 5 points ]
In: Computer Science
The goal is to design a program that prints out "unlock" when a 3 knock pattern is knocked on a sensor. this program will be ran on an arduino with a pizeo sensor.
In: Computer Science
In: Computer Science
(10) public double smallerRoot() throws Exception Depending on the equation ax^2 + bx + c = 0: if no roots, throw exception if single root, return it if two roots, return the smaller root if infinite root, return -Double.MAX_VALUE (11) public double largerRoot() throws Exception if no roots, throw exception if single root, return it if two roots, return the larger root if infinite root, return Double.MAX_VALUE (12) equals method This should OVERRIDE equals method from Object class return true if two expressions have same a, same b and same c (13) clone return a copy of the calling object (14) use javadoc style comments for the class, and the methods At minimum, include the author, parameters and return types for each method. (15) use javadoc to generate document for your class (16) test your class: you can write your own main to test your code; but you have to pass the test in QuadraticExpressionTest.java (17) submit a. QuadraticExpression.java b. QuadraticExpression.html on blackboard.
In: Computer Science
In: Computer Science
What makes functional values possible in Haskell?
In: Computer Science
1).Modify the project so that records are inserted into the random access file in ascending order using an insertion sort methodology with the Social Security Number acting as the key value. This requires defining the method compareTo() in the Personal and Student classes to be used in a modified method add() in Database. The method finds a proper position for a record d, moves all the records in the file to make room for d, and writes d into the file.
2. With the new organization of the data files. find() and modify() must also be modified. Both methods should now stop their sequential search when they encounter a record greater than the record looked for, or they reach the end of the file.
I am having trouble initializing the compareTo()
Personal.java
import java.io.*;
import java.util.Arrays;
import Student.Student;
public class Personal extends IOmethods implements DbObject
{
protected final int nameLen = 10, cityLen = 10;
protected String SSN, name, city;
protected int year;
protected long salary;
protected final int size = 9*2 + nameLen*2 + cityLen*2 + 4 +
8;
Personal() {
}
Personal(String ssn, String n, String c, int y, long s) {
SSN = ssn; name = n; city = c; year = y; salary = s;
}
public int size() {
return size;
}
public void writeToFile(RandomAccessFile out) throws IOException
{
writeString(SSN,out);
writeString(name,out);
writeString(city,out);
out.writeInt(year);
out.writeLong(salary);
}
public void writeLegibly() {
System.out.print("SSN = " + SSN + ", name = " + name.trim()
+ ", city = " + city.trim() + ", year = " + year
+ ", salary = " + salary);
}
public void readFromFile(RandomAccessFile in) throws IOException
{
SSN = readString(9,in);
name = readString(nameLen,in);
city = readString(cityLen,in);
year = in.readInt();
salary = in.readLong();
}
public void readKey() throws IOException {
System.out.print("Enter SSN: ");
SSN = readLine();
}
public void readFromConsole() throws IOException {
System.out.print("Enter SSN: ");
SSN = readLine();
System.out.print("Name: ");
name = readLine();
for (int i = name.length(); i < nameLen; i++)
name += ' ';
System.out.print("City: ");
city = readLine();
for (int i = city.length(); i < cityLen; i++)
city += ' ';
System.out.print("Birthyear: ");
year = Integer.valueOf(readLine().trim()).intValue();
System.out.print("Salary: ");
salary = Long.valueOf(readLine().trim()).longValue();
}
public void copy(DbObject[] d) {
d[0] = new Personal(SSN,name,city,year,salary);
}
public int compareTo(String p) {
}
}
Student.java
import java.io.*;
public class Student extends Personal {
public int size() {
return super.size() + majorLen*2;
}
protected String major;
protected final int majorLen = 10;
Student() {
super();
}
Student(String ssn, String n, String c, int y, long s, String m)
{
super(ssn,n,c,y,s);
major = m;
}
public void writeToFile(RandomAccessFile out) throws IOException
{
super.writeToFile(out);
writeString(major,out);
}
public void readFromFile(RandomAccessFile in) throws IOException
{
super.readFromFile(in);
major = readString(majorLen,in);
}
public void readFromConsole() throws IOException {
super.readFromConsole();
System.out.print("Enter major: ");
major = readLine();
for (int i = major.length(); i < nameLen; i++)
major += ' ';
}
public void writeLegibly() {
super.writeLegibly();
System.out.print(", major = " + major.trim());
}
public void copy(DbObject[] d) {
d[0] = new Student(SSN,name,city,year,salary,major);
}
public int compareTo() {
}
}
DbObject.java
import java.io.*;
public interface DbObject {
public void writeToFile(RandomAccessFile out) throws
IOException;
public void readFromFile(RandomAccessFile in) throws
IOException;
public void readFromConsole() throws IOException;
public void writeLegibly() throws IOException;
public void readKey() throws IOException;
public void copy(DbObject[] db);
public int size();
}
IOmethods,java
import java.io.*;
public class IOmethods {
public void writeString(String s, RandomAccessFile out) throws
IOException {
for (int i = 0; i < s.length(); i++)
out.writeChar(s.charAt(i));
}
public String readString(int len, RandomAccessFile in) throws
IOException {
String s = "";
for (int i = 0; i < len; i++)
s += in.readChar();
return s;
}
public String readLine() throws IOException {
int ch;
String s = "";
while (true) {
ch = System.in.read();
if (ch == -1 || (char)ch == '\n') // end of file or end of
line;
break;
else if ((char)ch != '\r') // ignore carriage return;
s = s + (char)ch;
}
return s;
}
}
Database.java
import java.io.*;
public class Database {
private RandomAccessFile database;
private String fName = new String();;
private IOmethods io = new IOmethods();
Database() throws IOException {
System.out.print("File name: ");
fName = io.readLine();
}
private void add(DbObject d) throws IOException {
database = new RandomAccessFile(fName,"rw");
database.seek(database.length());
d.writeToFile(database);
database.close();
}
private void modify(DbObject d) throws IOException {
DbObject[] tmp = new DbObject[1];
d.copy(tmp);
database = new RandomAccessFile(fName,"rw");
while (database.getFilePointer() < database.length()) {
tmp[0].readFromFile(database);
if (tmp[0].equals(d)) {
tmp[0].readFromConsole();
database.seek(database.getFilePointer()-d.size());
tmp[0].writeToFile(database);
database.close();
return;
}
}
database.close();
System.out.println("The record to be modified is not in the
database");
}
private boolean find(DbObject d) throws IOException {
DbObject[] tmp = new DbObject[1];
d.copy(tmp);
database = new RandomAccessFile(fName,"r");
while (database.getFilePointer() < database.length()) {
tmp[0].readFromFile(database);
if (tmp[0].equals(d)) {
database.close();
return true;
}
}
database.close();
return false;
}
private void printDb(DbObject d) throws IOException {
database = new RandomAccessFile(fName,"r");
while (database.getFilePointer() < database.length()) {
d.readFromFile(database);
d.writeLegibly();
System.out.println();
}
database.close();
}
public void run(DbObject rec) throws IOException {
String option;
System.out.println("1. Add 2. Find 3. Modify a record; 4.
Exit");
System.out.print("Enter an option: ");
option = io.readLine();
while (true) {
if (option.charAt(0) == '1') {
rec.readFromConsole();
add(rec);
}
else if (option.charAt(0) == '2') {
rec.readKey();
System.out.print("The record is ");
if (find(rec) == false)
System.out.print("not ");
System.out.println("in the database");
}
else if (option.charAt(0) == '3') {
rec.readKey();
modify(rec);
}
else if (option.charAt(0) != '4')
System.out.println("Wrong option");
else return;
printDb(rec);
System.out.print("Enter an option: ");
option = io.readLine();
}
}
}
UseDatabase.java
import java.io.IOException;
public class UseDatabase {
static public void main(String a[]) throws IOException {
// (new Database()).run(new Personal());
(new Database()).run(new Student());
}
}
In: Computer Science
One Problem/Question (Four Parts)
1 Sample run:
0
10
20
30
40
50
60
70
80
90
100
2 Sample run:
449
9
143
101
115
479
299
115
199
211
The Average of the numbers is: 212.0
3 & 4 Sample run:
say something: hello
you said : hello
say something: what's up?
you said : what's up?
say something: done
you said : done
Goodbye!
In: Computer Science
Write an iterative method countHighEarners() to return the number of nodes storing an high earner employee. Method countHighEarners()is in the class LinkedList that has private instance variable list of Node type. Class Node is private inner class inside of class LinkedList, and has public instance variables: data and next of Employee and Node type, respectively. In addition, class Node has constructor and toString method. See LinkedList class bellow on the right. Class Employee has getters for all data, method String toString() that returns string of all employee data, and method boolean isHighEarner() that returns true if employee's salary is above average, and false otherwise.
public int countHighEarners () { } |
public class LinkedList
{
private Node list;
public LinkedList()
{
list = null;
}
public Node getList()
{
return list;
}
. . .//other methods
// insert method countHighEarners here
private class Node
{
public Employee data;
public Node next;
public Node(Employee emp)
{
data = emp;
next = null;
}
public String toString()
{
return data.toString();
}
}
}
In: Computer Science
I NEED JAVASCRIPT PROGRAM
Chose an activity that you enjoy. It can be a sport that you
watch or participate in, collecting, hobbies, etc. Do
not use a collection of movies since we have covered that in the
assignment. Do not use the same topic as a
friend. (If two students that don’t know each other happen to
select the same topic, that is fine, since they will
naturally have different property names and values.)
1. Select some aspect of the activity and create an array of
objects denoting that aspect. For example, in
the case of movies, you could select movies themselves or you could
select movie stars, producers,
soundtracks, etc. There are many aspects of any activity that you
can use. Feel free to use the web to
research these values.
The array must contain at least 10 objects
The data must be actual data not just gibberish
Each object will have at least 4 properties with values
Each object in the array should have the same set of property names
with different values
At least one string value and one number value
Other properties can be of any JavaScript value type
2. Create a function that can be used to format your object in a
nice string format for output. This function
should be a pure function that takes one object as an argument and
return a string. The string can be
formatted in any way that you feel is appropriate for your data. It
must use one or more properties from
the object in the output string.
3. Create a new array from your array that only contains string
values produced by the above function. Sort
this array alphabetically and display an appropriate heading
followed by this list one string per line.
4. Prompt the user for a numeric value. Display a string (formatted
using the function above) for each of the
objects that have a property (you choose) that are greater or less
(up to you) the value provided by the
user. Be sure to provide a message if there are no objects that
match.
5. Calculate the average value based on some property of your
objects that makes sense. Output it with
descriptive text in a nicely formatted way.
Sample Output:
Movie Titles:
12 Angry Men (1957) by Sidney Lumet
Chak de! India (2007) by Shimit Amin
Hera Pheri (2000) by Priyadarshan
La Haine (1995) by Mathieu Kassovitz
Pulp Fiction (1994) by Quentin Tarantino
Schindler's List (1983) by Steven Spielberg
The Dark Knight (2008) by Christopher Nolan
The Godfather (1972) by Francis Ford Coppola
The Godfather: Part II (1974) by Francis Ford Coppola
The Good, the Bad and the Ugly (1966) by Sergio Leone
The Lord of the Rings: The Fellowship of the Ring (2001) by Peter
Jackson
The Lord of the Rings: The Return of the King (2003) by Peter
Jackson
The Shawshank Redemption (1994) by Frank Darabont
Movies newer than 2005:
Chak de! India (2007) by Shimit Amin
The Dark Knight (2008) by Christopher Nolan
The average age of these movies is: 31 years old.
In: Computer Science
Explain Parameter passing Semantics in Java/C++
In: Computer Science
what is Object-oriented modeling?
what is UML modeling?
What is the different between Object-oriented modelling and UML
In: Computer Science
In: Computer Science