Can somebody explain me what this code does in a few or one sentence?
#include <iostream>
#include <vector>
using namespace std;
int main () {
const int NUM_ELEMENTS = 8;
vector<int> numbers(NUM_ELEMENTS);
int i = 0;
int tmpValue = 0;
cout << "Enter " << NUM_ELEMENTS
<< " integer values..." << endl;
for (i = 0; i < NUM_ELEMENTS; ++i) {
cout << "Enter Value#"
<< i+1 << ": ";
cin >> numbers.at(i);
}
for (i = 0; i < (NUM_ELEMENTS /2); ++i) {
tmpValue = numbers.at(i);
numbers.at(i) =
numbers.at(NUM_ELEMENTS - 1 - i);
numbers.at(NUM_ELEMENTS - 1 - i) =
tmpValue;
}
system ("pause");
return 0;
}
In: Computer Science
Write a C program to take two integer arrays in ascending order and combine them in a new array in descending order. Remove any duplicates in the final array, if any. Your code must store the arrays as a linked list of objects, each put in a “struct.” All operations should also be carried out using linked lists.
Input: 2 sorted arrays, each on a new line.
Output: An array sorted in descending order, without duplicates.
There is a single white space after each number, even after the last number. There is no new line at the end. Use the following struct as a reference:
struct ELEMENT {
int value;
struct ELEMENT *next;
};
=== Sample test case 1 ===
Input:
2 15 18 34 67 87 88
3 8 18 33 67 89 91
Output:
91 89 88 87 67 34 33 18 15 8 3 2
=== Sample test case 2 ===
Input:
28 36 57 59 68 69 420
17 37 57 59 68
Output:
420 69 68 59 57 37 36 28 17
In: Computer Science
1.Read the Lab6-Background.pdf first.2.Start the “Stack Queue”
applet.3.The purpose of this exercise is to see how you could
reverse a list of names. Push the three names “Alice,” “Bob,” and
“Charles” onto the stack. When you pop the stack 3 times, what do
you see in the text field next to “Pop”?4.Write an algorithm in
pseudo-codethat would describe how to use a stack to reversea
sequence (list)of letters and print them. For instance, if the
original sequence is COMPUTERthe output will be RETUPMOC. Review
pages 249-250 of the textbook(Chapter8)to see the related sample
pseudo-codes.5.A palindrome word is one that has the same sequence
of letters if you read it from right to left or left to right(e.g.,
radar or madam). Describe (in terms of a pseudo-code) how you could
use a stack in conjunction with the original listto determine if a
sequence is a palindrome.Hint:Given that the letters have been
already assigned to both stackand the queueand these two data
structures are ready to be processed (compared).
In: Computer Science
In: Computer Science
UPDATE: Whole Code
How do I fix this Bold part "!= Null" ? its showing me Error? please Help
#include<iostream>
#include<string>
#include<string.h>
#include<fstream>
#include<stdlib.h>
#include<sstream>
using namespace std;
int main(){
string list[1000];
cout << "! Opening data file... ./Data.CS.SFSU.txt\n";
ifstream fin("Data.CS.SFSU.txt");
if(fin.fail()){
cout << "Error opening file\n";
return 0;
}
cout << "! Loading data...\n";
int count = 0;
while(getline(fin,list[count])!=NULL){
//cout << "--------------------\n";
count++;
}
cout << "! Loading completed...\n";
fin.close();
cout << "! Closing data file... ./Data.CS.SFSU1.txt\n";
cout << "-----DICTIONARY 340 C++-----\n";
while(true){
cout << "Search:";
string line;
getline(cin,line);
cout << "|" << endl;
stringstream ss(line);
string word1, word2, word3;
ss >> word1 >> word2;
if (ss >> word3 || (word2 != "noun" && word2 !=
"adjective" && word2 != "verb")){
cout << "Please enter a search key (and a part of
speech)\n";
}
else {
for (int i = 0; i<word1.length(); i++){
word1[i] = tolower(word1[i]);
}
int found = 0;
cout << count << endl;
for (int i = 0; i< count; i++){
char line2[200];
strcpy(line2, list[i].c_str());
char *ch = strtok(line2,"|");
//cout << ch << endl;
while (ch != NULL){
//cout << ch << endl;
//cout << ch1 << " " << endl;
if (strcmp(ch,(char *)word1.c_str()) == 0){
ch = strtok(NULL,"|");
char line[100];
strcpy(line, ch);
char *ch1 = strtok(line," ");
//cout << line << endl;
if (strcmp(ch1,word2.c_str()) == 0){
ch1 = strtok(NULL," ");
ch1 = strtok(NULL," ");
string s ="";
while (ch1 != NULL){
s = s + ch1 + " ";
ch1 = strtok(NULL," ");
}
cout << word1 << "[" << word2 << "] :"
<< s << endl;
found = 1;
break;
}
}
ch = strtok(NULL,"|");
}
if (found == 1)
break;
}
if (found == 0)
cout << "Not found\n";
}
cout << "|" << endl;
}
return 0;
}
In: Computer Science
In: Computer Science
Could i get a walk trough how to solve these questions. Note that is where the answer is meant to go.
Question 1
Say, instead of a separate variable (nItems), the number of items currently in the list are stored at index 0 in the array data, the actual values being stored starting at index 1. Complete the constructor that instantiates a list that can hold n values (excluding the item that holds the number of items currently in the list). That is, one should be able to add n values to the list before the need to grow it.
public class PackedArrayList {
public int[] data;
public PackedArrayList(int n) {
data = new int[ ];
data[0] = ;
}
}
Question 2
Complete the body of method addEnsureCapacity in the following
code:
public class MyArrayList {
public int[] data;
public int nItems;
public MyArrayList(int n) {
data = new int[n];
nItems = 0;
}
public void grow() {
//assume it increases capacity by 10
}
public boolean isFull() {
return (nItems == data.length);
}
public void addBasic(int val) {
data[nItems] = val;
nItems++;
}
public void addEnsureCapacity(int val) {
if( == false) {
;
}
else {
;
addBasic(val);
}
}
}
In: Computer Science
Assume a file containing a series of words is named words.txt and exists on the computer’s disk. Write a program that reads the data and counts the number of occurrences of each letter. The program should then displays how many times each letter appears in the sentence.
In: Computer Science
Review 19 In the discussion of TCP splitting in the sidebar in section 3.7 it was claimed that the response time with TCP splittting is approximately 4 * RTTFE +RTTBE + processing time. Please Justify this claim
Jim Kurose and Keith Ross,”Computer Networking – A Top-Down Approach”, Addison-Wesley, Seventh Edition, 2017. ISBN-13: 978-0-13-359414-0
In: Computer Science
In Python:
Define a function drawCircle. This function should expect a Turtle object, the coordinates of the circle’s center point, and the circle’s radius as arguments. This function should draw the specified circle. The algorithm should draw the circle’s circumference by turning 3 degree and moving a given distance 120 times. Calculate the distance moved with the formula 2.0*π*radius/120.0.
In: Computer Science
Write a complete C++ program that prompts the user for the price of the prix fixe menu choice. The program should then prompt the user for the number of guests in the party. The program should then calculate the bill including tax and tip then print the results to the console in the form of a receipt
For C++ Programming (I need it for C++ without using importing from java.)
In: Computer Science
This is Java programing. Complete Java program to produce the following output.
interface Register{
void course();
}
public class Interface1{
public static void main(String
args[]){
Register c=new A();
c.course();
Register s=new B();
s.course();
}
}
//output
I'm taking A
I'm taking B
In: Computer Science
In C++ Please
Problem 1: How to calculate a home's value
Housing economists have long used a home price/rent ratio as one
way to gauge whether or not home prices are inflated or
undervalued.
A housing P/E
The use of a price/rent ratio is analogous to employing a
price/earnings ratio for stocks. When a stock price is high, and
its earnings per share relatively low, the P/E is high. A high P/E
often indicates that the stock is too expensive, and the share
price is headed for a drop.
What someone is willing to pay to rent a place is that home's
"earnings." And, just as in the stock market, a high home price
related to the rental earnings mean homes values will probably
drop.
For a specific look at how a home's P/E is determined, let's
consider a home that is listed for either rent or sale in suburban
Chicago.
The home has been rented for the past three years for $1,600 per
month; so that is $19,200 per year. It is currently listed for sale
at $400,000. Dividing the price by the total annual rent of $19,200
gives a "housing P/E" of 20.83. According to Moody's Economy.com,
the long-run average housing P/E is 16, so a P/E of 20.83 suggests
that this home may be somewhat overpriced.
For this programming project you will read in a list of housing
prices and how much each house is rented for that are found in the
attached HousingPrices.txt file. The file looks like this:
713047 1246
1605787 1979
1174719 1879
1018239 1700
Where the first value on each line is the price of the home, and
the second number on each line is the price that this home
currently rents for per month.
Read these numbers in from the file into 2 separate arrays of size
100, since there are 100 home prices/rents in the file. Do this
part in your main method.
Then use a for-loop to loop through the arrays and for each pair of
values send them into a method that you will write called
"getHousingPE". Your method will have two parameters; the price of
the home and the current monthly rental rate of the home. Your
method will calculate and then return the homes “housing P/E”.
Check each homes returned P/E value and if the P/E value is greater
than 16 you should write to the output “House # is somewhat
overpriced”; where # is the number of the house in the file (1100).
If the P/E is greater than 19 then you should write to the output
“House # is way overpriced”. If the P/E is less than 12 then you
should write to the output "“House # might be a good deal”. And if
the P/E is less than 9 then you should write “Buy House #, it is a
deal”. If the P/E is between 12-16 then output "House # is
average".
Problem 2:
Determining Left or
Right
For this programming
project you are to
read in a list
of street addresses
and determine how
many of those
addresses are on
the right side of
the street, and how
many are on the
left. The street
addresses file is a
text file that
looks like:
6 S 33rd St
6 Greenleaf Ave
618 W Yakima Ave
74 S Westgate St
3273 State St
You can determine
if an address is
either on the left
or right side of
the street by
looking at the
number of the
address; all even
numbers are on the
right side of the
street, and all odd
numbers are on the
left side of the
street.
You will read your
data into 2 arrays;
an integer array to
hold the street
number, and a
String array to
hold the rest of
the address.
These will be
parallel arrays, meaning
the street number
and street address
of each index are
related to each
other.
Remember to draw a
picture so that you
can visualize this.
You will need to
write a method that
will determine if
each house is on
the left or right
side of the
street.
You will call this
method for every
street address, and
then keep a count
of how many houses
are on the left
and right sides of
the street.
The output should
be the street
number and address
and then whether
the house is on
the left or right
side of the
street:
Address Left/Right
6649 N Blue Gum St left
4 B Blue Ridge Blvd right
8 W Cerritos Ave #54 right
639 Main St left
…
The number of houses on the left and right sides of the street should also be output.
In: Computer Science
How many + operations occur when the following pseudocode is executed? What is the output? s ← 0, t ← 0 for i ∈ {1, ..., 6} do for j ∈ {1, ..., 6} do for k ∈ {1, ..., 6} do if i + j + k = 9 then t ← t + 1 s ← s + 1 print t / s
In: Computer Science