C/C++

Search for question

Questions & Answers

COMP 1130 Principles of Programming II Project 3 - File Conversion


4. Implement the function prototype for sequential search below, where a[] is the array to be searched through, t is the target value to be found, nis the array dimension. What is the complexity of the sequential search function? (10 Points)


1) Write, compile, and run a C++ program that specifies three one-dimensional arrays named price, amount, and total. Each array should be capable of holding 5 elements. Using a for loop, input values for the price and amount arrays. The entries in the total array should be the product of the corresponding values in the price and amount arrays (so total[i] = price[i] * amount[i]). After all the data has been entered, display the following output, with the corresponding value under each column heading:


7. Implement the function prototype for binary search below, where a[] is the array to besearched through, t is the target value, l and r are the left bound and the right bound of thearray. Given the following array with t=19, list all activations. What is the complexity ofthe binary search function? (15 Points) int search(int a[], int t, int l, int r){}


9. Implement the constructor and the display function of the array-based stack class below.(15 Points)


6. Given the following main function of a program named my list, if a user types the command line “./mylist 32 64 <enter>" for its execution, what will happen? (5 Points)int main(int argc, char **argv){


Exercise 1 ( Write a program that prompts the user to provide two characters, reads the two characters from the keyboard and prints on the screen the shape of a diamond using those characters.


3. Using C++ code, write a program to compute the product of the sums S, and S₂ of the even (indexes 0, 2, 4, 6, 8, ...) and odd (indexes 1, 3, 5, 7, 9, ...) elements, respectively, of a vector (or array) A of n = 75 random integers in the range [0,100]. First, A is created and initialized using 75 random integers in the function main. Secondly, a function even_sum receives, as parameters, A and n, and computes and returns S₁. Thirdly, a function odd_sum receives, as parameters, A and n, and computes and returns S₂. Lastly, a function finalize receives, as parameters, S. and S₂ and computes and prints the product of S₁ and S₂.


Assignment: Create a simple “shell” program that performs the following: 1. In a loop, prompt the user for a command and parameters. (fgets is a good tool for this) 2. When a command is given, insert the command and the parameters into an array of C strings. Use strtok to tokenize the string. Fork the process and have the parent wait for the child to complete. Have the child execute the given command using execvp execute command. Here’s POSIX documentation on exec. 3. Loop until the user enters “exit”. 4. Your program doesn’t have to do pipes(|), redirects (> or >>), or history1. Your program will prompt the user for input that will be executed. So if I was to type: ls -al you would execute the command and pass -al to the command (using execvp). The command ls with appropriate options would execute and display its output to the screen. The program will then prompt again and wait for the next input, until exit is entered. Read Programming Project 1 at the end of chapter 3 of our book. It’s similar to what I am asking you to do, except, you don’t have to do pipes, redirects, and history (it is discussed in the book though). Submit three files (simpleShellYourNAME.c, Makefile, and README2) as your assignment. Once you have the files on your machine, zip them and upload to WesternOnline. README file should explain what problem your program solves and how to compile and use it, and make, when executed, should compile everything correctly.


Programming Challenge: 21 - Random Number Guessing Game Enhancement One way to create a pseudo-random three digit number (and we are including one- and two-digit numbers as well) is rand () $1000. That gives numbers from 000 to 999, which is just what we want. As specified, have the program tell the player how many guesses were used. A good player should always be able to find a three-digit number in ten or fewer guesses.


No Question Found forC C

we will make sure available to you as soon as possible.