Write a loop that subtracts 1 from each element in lower

Assignment Help Computer Engineering
Reference no: EM132217601

in C++

1) Double any element's value that is less than minVal. Ex: If minVal = 10, then dataPoints = {2, 12, 9, 20} becomes {4, 12, 18, 20} Ex: Testing minVal = 4 and dataPoints = {1, 2, 3, 4, 5, -3} becomes {2 4 6 4 5 -6}

#include <iostream>
using namespace std;

int main() {
const int NUM_POINTS = 4;
int dataPoints[NUM_POINTS];
int minVal = 0;
int i = 0;

dataPoints[0] = 2;
dataPoints[1] = 12;
dataPoints[2] = 9;
dataPoints[3] = 20;

minVal = 10;

// student code here

for (i = 0; i < NUM_POINTS; ++i) {
cout << dataPoints[i] << " " ;
}
cout << endl;

return 0;
}

2) Write a loop that subtracts 1 from each element in lowerScores. If the element was already 0 or negative, assign 0 to the element. Ex: lowerScores = {5, 0, 2, -3} becomes {4, 0, 1, 0}.

#include <iostream>
using namespace std;

int main() {
const int SCORES_SIZE = 4;
int lowerScores[SCORES_SIZE];
int i = 0;

lowerScores[0] = 5;
lowerScores[1] = 0;
lowerScores[2] = 2;
lowerScores[3] = -3;

/* Your solution goes here */

for (i = 0; i < SCORES_SIZE; ++i) {
cout << lowerScores[i] << " ";
}
cout << endl;

return 0;
}

3)Add each element in origList with the corresponding value in offsetAmount. Print each sum followed by a space. Ex: If origList = {40, 50, 60, 70} and offsetAmount = {5, 7, 3, 0}, print:

45 57 63 70
#include <iostream>
using namespace std;

int main() {
const int NUM_VALS = 4;
int origList[NUM_VALS];
int offsetAmount[NUM_VALS];
int i = 0;

origList[0] = 40;
origList[1] = 50;
origList[2] = 60;
origList[3] = 70;

offsetAmount[0] = 5;
offsetAmount[1] = 7;
offsetAmount[2] = 3;
offsetAmount[3] = 0;

/* Your solution goes here */

cout << endl;

return 0;
}

Reference no: EM132217601

Questions Cloud

Write a program that prints the 128-character ascii table : Write a program that prints the 128-character ASCII table. It should print the table in eight tab-separated columns.
Write a statement that increments the value of the int : Write a statement that increments the value of the int variable total by the value of the int variable amount.
Prompt the user for a string that contains two strings : Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered.
How many users are on the local system : Which character is used to separate fields in /etc/passwd? How many fields are used to describe each user? How many users are on the local system?
Write a loop that subtracts 1 from each element in lower : Write a loop that subtracts 1 from each element in lowerScores. If the element was already 0 or negative, assign 0 to the element.
Implement a recursive descent parser for a logic calculator : The program should not exit when it encounters an error in the expression. Rather, it should output error information and then accept the next expression.
Explain what needs to be done to defend accounts : Eplain What You Have to do to Defend Accounts. Explain what needs to be done to defend accounts .
Give the associated range of destination host address : Consider a datagram network using 8-bit host addresses, i.e., IP addresses range from 0 to 255.
Write a function max that has two stringparameters : Write an expression that evaluates to true if the value of the string variable s1 is greater than the value of stringvariable s2 .

Reviews

Write a Review

Computer Engineering Questions & Answers

  Write algorithm for converting infix arithmetic expression

Write an efficient algorithm for converting an infix arithmetic expression to its equivalent postfix notation.

  What type of errors does the platform produces

Are there any security risks or concerns with the current platform? Are there any other technical performance issues related to the platform?

  Wap to implement a simplified lz encoding algorithm

Write a program to implement a simplified LZ encoding algorithm for a single scan line containing 1024 integer values, with each value in the range.

  Generating algorithm to read artibitary number of records

write down a detailed line listing the person's name and age. In addition, compute and output the following values: Number of males less than or equal to 21 yrs old.

  Design a usability questionnaire

Next you will design a usability questionnaire , administer it to at least 3 subjects, perform analysis on their responses, and compile a usability report.

  Calculate the sum of the squares of the elements

Write a function in C that takes three parameters: the address of a two - dimensional array of type int, the number of rows in the array.

  Discuss difference between cisc processor and risc processor

Discuss the differences between a CISC processor and a RISC processor. Tell what purpose a user mode and a supervisor mode might serve in the MC68000.

  Create er-modeling in ms visio

You have 2 tasks to create ER-Modeling in MS visio. Simple jab for the database expert that would take him 30 min to finish.

  Evaluation of vpn business sites using cisco devices

Prepare a technical plan for your chosen case study - Write down all the security and business objectives required based on give case study - The case studies focus on the design, implementation, and the evaluation of VPN business sites using Cisco d..

  Describe how osi model layers can effect a network design

There are two different types of switching technologies available in today's market. One lives on one layer, while the other resides in a different layer.

  What do you mean by an entity

How is it possible to get more information from the equal amount of data though using a database approach as opposed to a file approach.

  Theoretical implications of improper configuration

The Microsoft Baseline Security Analyzer (MBSA) is a powerful tool to identify missing security updates and common security misconfigurations in a networked environment. This lab will involve researching to understand the theoretical implications ..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd