C++ Only
Create a function named PrintStudents, which takes a string input filename and an integer minimum score value and a string output file name as a parameters. The function will read the student scores and names from the file and output the names of the students with scores greater than or equal to the value given. This function returns the integer number of entries read from the file. If the input file cannot be opened, return -1 and do not print anything to the file.
Read each line from the given filename, parse the data, process the data, and write the required information to the file.
Each line of the file contains <FIRST-NAME LAST-NAME>, <SCORE>, <SUBJECT> . Read and parse the data, then write to the output file the names and classes for scores matching the criteria.
Example: With the following data and value of 80:
Constance Shelton, 67, APPM 2002 Charlotte Edwards, 85, CSCI 1300 Alyssa Hill, 78, MATH 1000 Pat Owens, 75, HUMN 1342 Shannon Jimenez, 96, LING 2000 Kristen Swanson, 80, PSYC 1001 Jim Schwartz, 60, CVEN 3241
Your function should return 7 and output to the file should contain:
Charlotte Edwards, CSCI 1300 Shannon Jimenez, LING 200 Kristen Swanson, PSYC 1001
You only need to write the function code for PrintStudents. The split() function is provided, and functions as it does in the homework assignments, to make parsing the output easier. Recall that split takes a string s and splits it at the input delimiter sep, to fill the array words[] up to a capacity of max_words. The return value of split is the number of actual words the string is split into.
int split(string s, char sep, string words[], int max_words);
In: Computer Science
Step # 3 - Create the following structure in the home directory:
Refer to previous Steps 1 + 2 for reference. Do a tree to check your work as you go. No GUI, use command line only.
In: Computer Science
C#
- count =0;
- Create a 2d array "items".
string[,] items = new string[100, 4];
- Create a do while loop, when the user enters "0", stop the
loop.
- Users enter the item name, price, quantity, save this info and
subtotal to array.
- increase "count++"
-convert price(decimal, Convert.ToDecimal() ) and quantity(int)
to do multiplication
for subtotal
- create a for loop (with count ) to cycle through the "items",
display item name, price, quantity,
and subtotal.
accumulate subtotal
- Display total items, subtotal, total at the end.
Guide:
string[,] items = new string[100, 4];
int i, j, count;
/* input each array element's value */
for (i = 0; i < 100; i++) {
items[i,0] = Console.ReadLine("Enter Item Name: ");
if items[i,0] == "0"
break;
else
count++;
items[i,1] = Console.ReadLine("Enter Item Price: ");
items[i,2] = Console.ReadLine("Enter Item Quantity: ");
items[i,3] =
(Convert.ToDouble(items[i,1])*Convert.ToDouble(items[i,2])).toString();
}
/* output each array element's value */
for (i = 0; i < count; i++)
{
for (j = 0; j < 4; j++) {
Console.WriteLine(items[i,j], " ");
}
}
In: Computer Science
Write an algorithm to determine if two binary trees are identical when the ordering of the subtrees for a node is ignored. For example, if a tree has root node with value R, left child with value A and right child with value B, this would be considered identical to another tree with root node value R, left child value B, and right child value A. Make the algorithm as efficient as you can. Analyze your algorithm’s running time. How much harder would it be to make this algorithm work on a general tree?
In: Computer Science
Complete the following tasks. In each exercise, represent your answer only in DBDL. Do not use diagrams a this point. Submit either a text file or a Word document with your work. Make sure you follow chapter 6's DBDL notation
(****** Just to clarify: this is the first question on Page
220. It says to 'produce the following reports', but what you are
asked to do is use DBDL notation to create 5 tables: Guide,
Trip, Customer, Reservation and TripGuides
Make sure to list the FK where they belong ******)
In: Computer Science
How can a Targeted worm or virus avoid detection by a virus scanner? Give the most relevant answer.
In: Computer Science
Describe an algorithm to solve the variant of the Towers of Hanoi in as few moves as possible. Prove that your algorithm is correct. Initially, all the n disks are on peg 1, and you need to move the disks to peg 2. You are not allowed to put a bigger disk on top of a smaller disk.
1. Suppose you are forbidden to move any disk directly between peg 1 and peg 2, and every move must involve (the third peg). Exactly (i.e., not asymptotically) how many moves does your algorithm make as a function of n?
In: Computer Science
Write a program that reads a file line by line, and reads each line’s tokens to create a Student object that gets inserted into an ArrayList that holds Student objects. Each line from the file to read will contain two strings for first and last name, and three floats for three test grades. After reading the file and filling the ArrayList with Student objects, sort the ArrayList and output the contents of the ArrayList so that the students with the highest average are listed on top.
The Student class should have instance data for first and last name, and a float array to hold three test grades. Create getters and setters for first and last name. Create one getter and one setter for inserting tests into the array. Don’t forget to verify that the quiz grades are within a range that makes sense before you insert them into the array. Also, verify that you do not go outside the index range of the array when inserting quizzes. Create a method to calculate and return test average. Also, override the toString method and the equals method to something that make sense. Also, implement the Comparable interface on the Student class so that when you compare Student objects by comparing the student's test average. If the average is the same when comparing, then compare the last names. If the last names are the same, then compare the first names.
Here is the file that the program should read:
Text File:
Frank Hanford 78.5 65.9 98.2 John Blake 93.1 85.9 89.1 Alex Sanders 87.1 56.9 67.2 Jane Hope 72.1 85.1 77.9 Donald Davidson 85.1 72.1 77.9 Alan Davidson 77.9 72.1 85.1 Perkins Jenkins 87.5 75.9 90.1 Barbara Thompson 90.1 89.9 99.7 Michael Jones 78.1 69.9 81.2
In: Computer Science
Pick one area where you think Blockchain Technology could be proposed as a solution and briefly explain your proposed solution. Your final document should include an Abstract and a Conclusion
In: Computer Science
The Lucas Numbers are a sequence very similar to the Fibonacci Sequence, the only difference being that the Lucas Numbers start with L0 = 2 and L1 = 1 as opposed to Fibonacci’s F0 = 0 and F1 = 1. Concretely, they are defined by L0 = 2, L1 = 1, and Ln := Ln−1 + Ln−2 for n > 1. Write a function in C++ that takes an integer argument N and returns the sum of the first N + 1 even Lucas Numbers.
In: Computer Science
Write a C code to let the main thread create N child threads, where each created thread will randomly generate an integer between 0 to 10 and put it into a global array variable. After that, the main thread will calculate the sum of all the generated integers. N should be input as a command line argument.
Complete the following C code by filling all “???”s in the code sketch. NOTE: when you compile the code, you need to add the parameter “-lpthread” to “gcc”, e.g., “gcc YourCode.c -lpthread”
// include the header file that allows us to use pthread #include <???> #include <stdio.h> // include the header file that allows us to use dynamic memory management #include <???> // define a pointer to point to an array to hold the randomly generated integers int *a; // define the function used to create a thread ???runner(???param); int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "usage: %s <integer value>\n", argv[0]); return -1; } int N = atoi(argv[1]); if (N<=0) { fprintf(stderr, "%d must be > 0\n", N); return -1; } // define an array to hold the threads to be created ??? workers[N]; // define a set of thread attributes for creating threads ??? attr; // define a variable later used for “for” loop int i; // use dynamic memory management to create an array to hold the integers a = ??? ; // seed the random number generator srandom((unsigned)time(NULL)); // initialize the default thread attributes ??? // use “for” loop to create the threads, where the index of the created thread in workers // array should be passed to the thread as the parameter ??? // use “for” loop to wait for all the threads to exit ??? // calculate the sum int sum = 0; for (i=0; i<N; i++) sum += a[i]; printf("sum = %d\n", sum); // free the dynamically created array ??? } // The created thread will start its execution from this function ??? runner(??? param) { // get the index of the thread in workers array and put it to “thread_index” int thread_index = ??? ; // randomly generate an integer between 0 to 10 a[thread_index] = random()%11; // print the information on the screen printf("Thread %d generates integer %d ...\n", thread_index, a[thread_index]); // terminate the thread ??? }
In: Computer Science
Please create a C++ program that will ask a high school group that is made of 5 to 17 students to sell candies for a fund raiser. There are small boxes that sell for $7 and large ones that sell for $13. The cost for each box is $4 (small box) and $6 (large box). Please ask the instructor how many students ended up participating in the sales drive (must be between 5 and 17). The instructor must input each student’s First name that sold items and enter the number of each box sold each (small or large). Calculate the total profit for each student and at the end of the program, print how many students participated and the total boxes sold for each (small and large) and finally generate how much profit the group made.
In: Computer Science
In python, write a program that asked the user to enter the monthly costs for the following expenses incurred from operating his automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should display total monthly cost and annual cost. Also, should contain main and calcExpenses functions, calcExpenses should only calculate the expenses and everything else should happen in the main function.
In: Computer Science
Please comment, exactly how this program works?
#include <stdio.h>
int main()
{
int i,j;
int a[1000];
for(i=0;i<1000;i++)
a[i]=1;
for(i=2;i<1000;i++)
{
if(a[i]==1){
for(j=i+1;j<1000;j++)
{if(j%(i)==0)
a[j]=0;
}
}
}
printf("print numbers are:\n");
for(i=2;i<=1000;i++)
if(a[i]==1)
printf("%d, ",i);
}
In: Computer Science
Briefly explain the terms used in object-oriented programming with examples.
In: Computer Science