Using C++,
Write a program that will use pointer syntax to access variables, dynamically allocate memories, and pass pointers to functions.
1. The program should ask the user to enter a size to the array.
2. The program should dynamically allocate an array with the size.
3. The program should then ask user to input values to the array
4. The program should then find the maximum, display all elements forward and reversed using two different ways of pointer access
5. The program must use functions with pointers as parameters.
6. The manipulation/access of the array must be done through pointer syntax.
7. Your main function should only declare the variables and call the functions.
Variable:
You’ll need the following pointer to be declared in your main function.
float * ptData;
Data Validation:
1. The size of the array cannot be less or equal to 1 (E.g. 2, 5, 100 is fine, but 1 or 0 is no acceptable).
2. Check if pointer has successfully allocated the array.
Functions:
You should have separate functions to handle user input, maximum, and display the array (all the values needs to be returned to the function call, you need to have pointer as the input parameter). Main function should only call other functions.
|
Function Header |
Explanation |
|
void getSize(int * ptr) |
This function will ask user to enter a size to the array. The size of the array cannot be less or equal to 1. For example: 2, 5, 100 is fine, but 1 or 0 is no acceptable. |
|
float * getValues(const int SIZE) |
This function will declare and use a pointer to dynamically allocate an array with the size user has entered. The pointer should be returned to the function’s call. Check if pointer has successfully allocated the array. |
|
float getMax(const float * ptr, const int SIZE) |
This function will find and return the maximum value of the array using pointer syntax. |
|
void displayForward(const float * ptr, const int SIZE) |
This function should display all array elements forward (from the first to the last) |
|
void displayBackward(float * const ptr, const int SIZE) |
This function should display all array elements backward (from last to the first) You are required to use the following pointer and loop to accomplish this task. float * ptr2 = ptr + SIZE; while (ptr < ptr2) |
Sample Output:
|
Please enter a size to the array: -9 !!!Error: an array’s size cannot be less or equal to 1 Please enter a size to the array: 6 Please enter all values of the array: Value 1: 4 Value 2: 5 Value 3: 7 Value 4: 2 Value 5: 1 Value 6: 8 Displaying all values forward: 4 5 7 2 1 8 Displaying all values backward: 8 1 2 7 5 4 The maximum value of this array is: 8 |
In: Computer Science
A load ZL = 80− j100 is located at z = 0 on a lossless 50-
line.
The operating frequency is 200 MHz and the wavelength on the line
is 2 m.
(a) If the line is 0.8 m in length, use the Smith chart to find the
input impedance.
(b) What is s? (c) What is the distance from the load to the
nearest voltage
maximum? (d) What is the distance from the input to the nearest
point at which
the remainder of the line could be replaced by a pure
resistance?
In: Computer Science
Using C#
Create a class called CreditAccount. When user create this account, she/he need to enter sum of credit and loan repayment period in months. Monthly payment need to calculate using bank percentage. You must come up with a formula for calculating percentage, you can use any formula, you want.
In: Computer Science
This week we really want to learn about a file I/O in Java.
In Java:
1) Create a plain empty text file named contacts.
2) Populate the text file with a person's name and account number on each line(Joe Doe 123456789). Create 10 accounts.
3) Store that file in the same location as your project
4) Write a program that will find that file and load it into the computers memory.
5) Read each line of the file and print the associated name but NOT the account number (remember the account number is 9 characters fixed)
In: Computer Science
Write a python program to create a list of integers using random function. Use map function to process the list on the series: x + x2/2! + x3/3! + ….n and store the mapped elements in another list. Assume the value of n as 10
In: Computer Science
For this lab you will implement the class Ball which represents a toy ball. Ball should have a method bounce() whose return type is void, and should have an integer member bounces that counts the number of times the ball has been bounced. Ball should also have a static method named getTotalBounces which counts the total number of times that any Ball object has been bounced. To do this, you will want to include a static integer member totalBounces which counts the total number of bounces. Once implemented the following code in the main of UseBall should output the number 2 (You should create UseBall.java as well, right?): Ball b1 = new Ball(); Ball b2 = new Ball(); b1.bounce(); b2.bounce(); System.out.println(Ball.getTotalBounces()); Next, we will add some functionality to Ball. First, implement a method void reset(int count) which sets bounces to the value provided in count. How does this affect totalBounces? Next, include an integer variable to keep track of the total number of balls which have been created. Should this variable be static or dynamic? Use this variable to implement the static method getAverageBounces() which returns the average of the number of times that any ball has been bounced. Finally, as a challenge, try to implement the static method bounceAll() which bounces each of the balls at once. This will be difficult unless you include one more static integer member in the class - and even then it might be a bit tricky. Give it your best shot, and don't hesitate to ask the lab assistants for help!
In: Computer Science
In Java:
1) Create a new eclipse project.
2) Create a basic SWING window
3) Create a Label Called Name
4) Create a Text Field for entering the name
5) Create a Text Field for entering and email
5) Create a text area to push the results to
6) Create two buttons, one that says submit and the other that says clear.
7) When the user enters their name and email, they should press submit and see the Text area populate with the data they submitted.
8) When the user presses clear it should clear any text from all fields.
In: Computer Science
Translate following C# code into MIPS assembly language
int recursive(int x) {
return (x >= 0xFF) ? (recursive(x - 3) + recursive(x - 2))
: ((x >= 0xF) ? recursive(x - 1) + 1 : 1);
In: Computer Science
As I was on a hike the other day I came across a small child in the woods. He told me his life story, with special mention of his disabled sister who loves flowers, and asked me for a favor. He wanted a way to organize the flowers that he picks for her each day and perform a few basic tasks with them, along with a few restrictions. It is our goal to help him out! • He can only carry 25 flowers as adding any more causes many of them to become crushed. • All flowers should be able to be displayed • He should be able to add and remove flowers by using their name. • He needs to be able to search for a specific type of flower in his pack in case his sister has a special request. • He needs to be able to sort flowers by their names alphabetically in ascending order (A-Z) • He needs to show how many of each flower he has in his pack. Now, I have started a simple program which will serve as guidance for you, please help me finish it. (Please don’t modify the code that I give you, just add your code where required) Submit 1 file: Assignment1.java import java.util.Scanner; public class Assignment01Driver { public static void main(String[] args){ new Assignment01Driver (); } // This will act as our program switchboard public Assignment01Driver (){ Scanner input = new Scanner(System.in); String[] flowerPack = new String[25]; System.out.println("Welcome to my flower pack interface."); System.out.println("Please select a number from the options below"); System.out.println(""); while(true){ // Give the user a list of their options System.out.println("1: Add an item to the pack."); System.out.println("2: Remove an item from the pack."); System.out.println("3: Sort the contents of the pack."); System.out.println("4: Search for a flower."); System.out.println("5: Display the flowers in the pack."); System.out.println("0: Exit the flower pack interfact."); // Get the user input int userChoice = input.nextInt(); switch(userChoice){ case 1: addFlower(flowerPack); break; case 2: removeFlower(flowerPack); break; case 3: sortFlowers(flowerPack); break; case 4: searchFlowers(flowerPack); break; case 5: displayFlowers(flowerPack); break; case 0: System.out.println("Thank you for using the flower pack interface. See you again soon!"); System.exit(0); } } } private void addFlower(String flowerPack[]) { // TODO: Add a flower that is specified by the user } private void removeFlower(String flowerPack[]) { // TODO: Remove a flower that is specified by the user } private void sortFlowers(String flowerPack[]) { // TODO: Sort the flowers in the pack (No need to display them here) - Use Selection or Insertion sorts // NOTE: Special care is needed when dealing with strings! research the compareTo() method with strings } private void searchFlowers(String flowerPack[]) { // TODO: Search for a user specified flower } private void displayFlowers(String flowerPack[]) { // TODO: Display only the unique flowers along with a count of any duplicates /* * For example it should say * Roses - 7 * Daffodils - 3 * Violets - 5 */ } }
In: Computer Science
Project name: Practical1LastFirst
You are being asked to create a program related to tracking players on a ringette team. It is important to create as per the requirements document. The details of the RingettePlayer class are provided in the following class diagram.
|
RingettePlayer |
|
-firstName: String -lastName: String -allergies: String -jerseyNumber: int -birthYear: int |
|
Constructors +RingettePlayer() +RingettePlayer(String, String) +RingettePlayer(int) +RingettePlayer(String, String, String, int) +getters/setters for all +getInformation():void +display():void +toString(): String |
Default Values for Attributes
When values are not provided for attributes, the following are the values that should be set for the attributes. Note that these are the only attributes that are to be in the class.
Constructor Details
Create four constructors in the RingettePlayer class based on the following requirements.
Controller Class Functionality
In the main method create three object based on the following specifications. You can use your own name for the variable name.
Additional Requirements
|
Ringette Players Name: Brielle Jones Jersey Number: 0 Allergies: Birth Year: 0 Name: Marley Stephens Jersey Number: 9 Allergies: Dust Birth Year: 0 Name: Sarah Miles Jersey Number: 15 Allergies: Nuts Birth Year: 2009 |
|
Allergies for all players: Dust Nuts |
In: Computer Science
Need the slack clone by using react.
Create slack clone by using ReactJS library. Use material UI for Design improvements and Icons.
Urgently required before evening... Don't give useless answers. I'll downvote if not according to expectations.
In: Computer Science
i need this program to also print out the number of combinations
#include <stdio.h>
#include <string.h>
#define N 10
void generate(char *array, int n)
{
if (n==0)
{
printf("%s\n",array);
return;
}
for (int i = 0; i < n; ++i)
{
// generate all of the permutations
that end with the last element
generate(array, n-1);
// swap the element
char temp = array[n-1];
array[n-1] = array[(n%2)*i];
array[(n%2)*i] = temp;
}
}
int main(int argc, char const *argv[])
{
char array[N];
printf("Enter word: ");
scanf("%s",array);
generate(array, strlen(array));
return 0;
}
In: Computer Science
You will be writing the function definition and the main function with the function call.
Be sure to write the function definition below the main function.
The function prototype has been provided, you may add the prototype to you answer.
You do not need to add the preprocessor directives like #include<stdio.h>.
Write the function definition for UpdateGrade . The function will take two arguments, a double called originalGrade a pointer to a double called newGradePtr.
This function will have a void return type.
Inside the UpdateGrade function:
In the main function
#include<stdio.h>
//function prototypes
void UpdateGrade(double originalGrade, double *newGradePtr);
in C programming language
In: Computer Science
1. Given a vector, a, of length n, write down the MATLAB expressions that will correctly compute the following:
a. ln (3 + a + a2 )
b. ea (1 + cos(3a))
c. cos2 (a) + sin2 (a)
d. tan-1 (a)
Test that your solution works for a = 1:0.2:2
2. a. Create a vector of odd whole numbers between 10 and 40.
b. Create a vector of even whole numbers between 25 and 35.
3. Plot a Straight line with slope m=0.5 c=-2 at the following coordinates X=0, 4,5,7,9,10,12,15.
4. Plot y=sin x, 0<=x<=4pi, taking 50,100 linearly spaced points in the given interval.
In: Computer Science