[Computer Science Question]
Compare and Contrast the trade-offs associated with using C++ in
comparison to Python. How do the characteristics of the languages
impact the amount of memory each language occupies. How do memory
considerations impact each languages real world
implementations?
In: Computer Science
In this assignment you must submit TWO different programs both of which accomplish the same thing but in two different ways.
Using NetBeans, create a program that prompts the user for a sentence. Then the program displays the position of where the lowercase letter 'a' appears everywhere in the sentence. Here is a sample of the input and output:
Enter a sentence
for the night is dark and full of terrors.
The lowercase letter 'a' appears at character position 18
The lowercase letter 'a' appears at character position
22
Write TWO different programs that accomplishes the above using different techniques. Take a look at the JavaDocs for the String methods available to you. For example, one way is you might use the 'charAt()' method while your second program uses 'indexOf()'.
please send me the solution in java as soon as possible.
In: Computer Science
what is the time complexity of those ?
//TODO - Question 18
public static int[][] fillRandomArray4(int n) {
int[][] arr = new int[n][n];
for(int i = 0; i < arr.length;
i++) {
arr[i] = new
int[] {(int)(Math.random() * 101),
(int)(Math.random() *
101),
(int)(Math.random() *
101)};
}
return arr;
}
//TODO - Question 19
public static int factorial(int n) {
if(n == 1 || n == 0) {
return 1;
}
return n * factorial(n-1);
}
//TODO - Question 20 - assume str.length() == n
public static boolean isPalindrome(String str) {
if(str.length() == 0 ||
str.length() == 1) {
return
true;
}
if(str.charAt(0) !=
str.charAt(str.length()-1)) {
return
false;
} else {
return
isPalindrome(str.substring(1,str.length()-1));
}
}
In: Computer Science
Given the following inheritance Diagram structure: Fruit: Apple and Orange, Apple: GoldenDelicious and MacIntosh Create a C++ Program that simulate the inheritance structure above. Fruit class should have at least two attributes name and color, getters and setters in addition to a method display() just to display the fruit details. Define the classes Apple, Orange, GoldenDelicious and MacIntosh All of which you can choose the attributes, constructors and methods of your choice, but all should have a redefinition of the method display() In the main create different objects of different classes, assign names and colors and demonstrate the dynamic binding call of the method display using (Polymorphism) GoldenDelicious MacIntosh Fruit Apple Orange
In: Computer Science
Execute SQL queries to get the countries in which the population has fallen from one year to the next, and the years in which it has occurred. Dump the output in the following format:
| country | year | population | year | population |
| 1 | 2005 | 82500849 | 2006 | 82437995 |
| 1 | 2006 | 82437995 | 2007 | 82314906 |
(...)
And so on.
These are the SQL files:
Tables: pastebin.com/xw0j1NAM
Data: pastebin.com/hnpFT3QR
In: Computer Science
Exercise 12.4: Use a browser's developer tools to view the DOM
tree of the document in Fig. 12.4. Look at the document tree of
your favorite website. Explore the information these tools give you
in the right panel(s) about an element when you click it.
Please use the Chrome browser:
Write a paragraph or two about what you learned about using the Chrome developer tools.
In: Computer Science
C++ You should have one main function + 4 other functions for your submission for this lab. you have no need for extra functions beyond that, and you should not have less. You may use any pre existing functions already defined in class or a previous lab.
-Write a function storeTotal(,) that takes two arguments of type double, and has a return type of type Boolean. This function will take the number 256 and divide it by the second parameter, and add the result to the first parameter. It will return true afterwards.
-You should be making mindful decisions of which parameters should be call by value and which should be call by reference.
-If dividing by the second parameter would result in a run time error, the program does not do the calculation, and instead returns false.
-Ask the user to input two numbers, one at a time, discarding excess input each time.
-The program should keep looping until the user enters valid input.
-Once the user enters input, call function storeTotal appropriately.
-Whether storeTotal runs successfully (returns true) or not (returns false), display an appropriate message.
-Output the results of the variable that is cumulating value. This number is ALWAYS displayed in scientific notation, accurate to 3 decimal places
Repeat this 2 times.
Sample Output
How much do you already have? A
Invalid Input!
How much do you already have? Bck
Invalid Input!
How much do you already have? 42.4
What is the split factor? ,!
Invalid Input!
What is the split factor? 3.5
You now have 1.155e+002
How much do you already have? 35.6
What is the split factor? 0
That didn't go well, you still have 3.560e+001
*Explanation* 256/3.5 and then added to 42.4 gives 115.54, which, in scientific notation, gives the output above.
*Note* How scientific notation is displayed can vary from compiler to compiler, as long as you are getting it done through proper knowledge of C++ then the output does not need to look exactly the same.
In: Computer Science
/*instructions: please do not change the general structure of the code that I already have
please write it in C programming
Define the interface for a queue ADT and implement it in two
ways: one with a dummy node (or nodes) and one without.
In addition to the two standard queue functions you’ll need a
function to create/initialize an empty queue,
a function to free an existing queue (which may not be
empty),
and a function to return the size (number of keys) in the
queue.
All functions should be as efficient as possible, e.g., the
complexity of enqueue and dequeue must be O(1).
An additional requirement is that the underlying data structure
should not be a doubly-linked list.*/
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int num;
struct node *next;
}Node;
typedef struct{
Node* front
Node* rear;
int size;
}Queue;
//Define the interface for a queue ADT
Queque* initializeQueque()
{
}
Queque* insert(int item)
{
}
Queque* delete()
{
}
void printList(Node* Q)
{
}
//get the size of the queque at postion [-1]
//return the size (number of keys) in the queue.
int getsize(Node* Q)
{
}
int main()
{
int option,item;
Node* Queque;
while(1){
printf("1.Insert number to queque\n2.Delete number from
queque\n3.Display numbers in queque\n4.Exit\nEnter a
option:");
scanf("%d",&option);
switch(option){
case 1:
printf("Enter the number:");
scanf("%d",&item);
Queque=insert(item);
break;
case 2:
Queque=delete();
break;
case 3:
printList(Queque);
break;
case 4:
return 1;
default:
printf("\nWrong input!\n");
break;
}
}
}
In: Computer Science
Modify the program so that, rather than printing data directly to the screen, it will read the data into an array of car structs and then print out the contents of the array.
#include "car.h" #include <iostream> #include <iomanip> #include <fstream> #include <string>
Car GetCar(ifstream& dataIn);
// Pre: File dataIn has been opened.
// Post: The fields of car are read from file dataIn.
void WriteCar(ofstream& dataOut, Car car);
// Pre: File dataOut has been opened.
// Post: The fields of car are written on file dataOut,
// appropriately labeled.
int main ()
{
Car car;
ifstream dataIn;
ofstream dataOut;
dataIn.open("cars.dat");
dataOut.open("cars.out");
cout << fixed << showpoint;
car = GetCar(dataIn);
while (dataIn)
{
car.price = car.price * 1.10f;
WriteCar(dataOut, car);
car = GetCar(dataIn);
}
return 0;
}
//*****************************************************
Car GetCar(ifstream& dataIn)
{
Car car;
dataIn >> car.customer;
dataIn >> car.price >> car.purchased.day
>> car.purchased.month >> car.purchased.year;
dataIn.ignore(2, '\n');
return car;
}
//*****************************************************
void WriteCar(ofstream& dataOut, Car car)
{
dataOut << "Customer: " << car.customer << endl
<< "Price: " << car.price << endl
<< "Purchased:" << car.purchased.day << "/"
<< car.purchased.month << "/"
<< car.purchased.year << endl;
}
.h file
#include <string>
struct PersonType {
std::string firstname;
std::string lastname;
};
struct Date
{
int month;
int day;
int year;
};
struct Car
{
float price;
Date purchased;
PersonType customer;
};
In: Computer Science
create a Java application program that will add up the cost of three items, then print the final total with sales tax.
You should begin by prompting the user to enter three separate prices for three items that are being purchased. For each item you should ask for (in this order) the quantity of the product and the price of the product.
The program should compute, and be able to print to the screen:
the subtotal (the total amount due before tax)
sales tax (the amount of sales tax that will be added, assume 7% tax rate)
total due (subtotal + sales tax)
The following is an example of what your MIGHT see on the screen when your program runs. The exact output depends on what values that the user types in while the program runs. The user's values are shown below in italics:
Enter the quantity of the first product: 3
Enter the price of the first product: $5.25
Enter the quantity of the second product: 2
Enter the price of the second product: $1.83
Enter the quantity of the third product: 7
Enter the price of the third product: $0.89
Subtotal: $25.64
Sales Tax: $1.79
Total Due: $27.43
can post a screen shot of your java program Would like to learn the steps, i am doing intro to Java programing
In: Computer Science
You must use C Language.
End Goal:
HATFIELD, HEIDI
KAISER, RUSSELL
LIPSHUTZ, HOWARD
PENKERT, DAWN
WRIGHT, ELIZABETH
The user inputs the students first name and last names separately but within one loop. The loop should end when the user presses enter on the first name without entering any text. Upon completing entry of data, the output pictured above should display on the output.
Using the code given, follow the steps:
1. You should be able to enter up to 20 student first names. Also, change the input array to an appropriate size of 18 for the length of the first name. Use a meaningful name for the storage of first names array. Change prompts as needed. The loop should exit when the user presses enter when inputing the first name without adding any text. Compile and make sure it works from main(). At this point, you should be able to enter and alphabetize a list of up to 20 first names! Alphabetizing the first name is just a test!!! In the end, you will alphabetize the whole name string.
2. Add another array and get input for last name INSIDE the loop for your first names. This last name array will also be an array of 20 elements but with room for up to 25 characters. Again, do not use another loop! Just add code to input the last name to the first loop. The program should now ask the user to input the student's first name and then last name in that order for each individual. Then the program will loop to continue adding student names until the user presses enter on the student's first name. Make sure the last name is converted to all caps. You do not need to alphabetize this array, but you may want to print it out to make sure everything is working just as a test.
3. Make changes to convert the first name to all upper case using a function. (Example: User enters bob on the first name, then on the last name enters jenkins, it will look like Bob Jenkins instead of bob jenkins)
Last step: Combine last and first into an third array. This code is most easily added to the first loop. You just had the user enter first and last names. So the current value of the subscript used for these arrays can be used to combine content and store in the third array. Alphabetize THIS array (instead of the first name array) which means you need to send a different pointer to the stsrt() function. Print out the end result. Test that everything is working on this program.
Given Code:
void rollsheet(void) {
int ct = 0;
char *ptstr[LIMIT];
char input[LIMIT][SIZE];
int k;
printf("Enter up to %d student names, and I will sort them!\n",
LIMIT);
printf("To stop, press the Enter key at a line's start.\n");
while (ct < LIMIT && s_gets(input[ct], SIZE) !=
NULL
&& input[ct][0] != '\0')
{
ptstr[ct] = input[ct]; /* set ptrs to strings */
ct++;
}
stsrt(ptstr,ct);
puts("\nHere's the sorted list:\n");
for (k = 0; k < ct; k++)
puts(ptstr[k]) ; /* sorted pointers */
}
void stsrt(char *strings[], int num)
{
char *temp;
int top, seek;
for (top = 0; top < num-1; top++)
for (seek = top + 1; seek < num; seek++)
if (strcmp(strings[top],strings[seek]) > 0)
{
temp = strings[top];
strings[top] = strings[seek];
strings[seek] = temp;
}
}
char * s_gets(char * st, int n)
{
char * ret_val;
int i = 0;
ret_val = fgets(st, n, stdin);
if (ret_val)
{
while (st[i] != '\n' && st[i] != '\0')
i++;
if (st[i] == '\n')
st[i] = '\0';
else // must have words[i] == '\0'
while (getchar() != '\n')
continue;
}
return ret_val;
}
In: Computer Science
Java Programming:
In the program shown below, I want to print the result in the output file. The main static method calls a method, displaySum which adds two integers and prints the result (sum). The problem is that I am not able to use "outputFile.print()" inside displaySum to print the content as the output file. I also want to display the content of two other methods, but I am facing this difficulty.
** DisplayOutput.java **
import java.io.*;
public class DisplayOutput
{
public static void main(String[] args) throws
IOException
{
FileWriter fw = new
FileWriter("output.txt");
PrintWriter outputFile = new
PrintWriter(fw);
outputFile.println("Suppose two
inetegers are 2 and 3.");
outputFile.println("Display the sum
of two inetegers (2 and 3).");
displaySum(2,3);
outputFile.close();
}
private static void displaySum(int n1, int n2)
{
int sum = n1 + n2;
outputFile.print("Sum of two integers (2 and 3)
is: " + sum); // Error: outputFile cannot be
resolved
}
}
In: Computer Science
In: Computer Science
Write a Java program called Numbers that reads a file containing a list of numbers and outputs, for each number in the list, the next bigger number. For example, if the list is
78, 22, 56, 99, 12, 14, 17, 15, 1, 144, 37, 23, 47, 88, 3, 19
the output should look like the following:
78: 88
22: 23
56: 78
99: 144
12: 14
14: 15
17: 19
15: 17
1: 3
144: 2147483647
37: 47
23: 37
47: 56
88: 99
3: 12
19: 22
NOTE: If there is no bigger number in the sequence, just display the value of Integer.MAX_VALUE .
The output should be shown on the screen and also saved in a file.
Program Design
Additional Requirements
The output of your program should exactly match the sample program output given at the end
In: Computer Science
(10) Let L = { <D> | D is a DFA that accepts sR whenever it accepts s } . Show that L is Turing-decidable.
In: Computer Science