Vector testGrades contains NUM_VALS test scores. Write a for loop that sets sumExtra to the total extra credit received. Full credit is 100, so anything over 100 is extra credit.

Answers

Answer 1

Question:

Vector testGrades contains NUM_VALS test scores. Write a for loop that sets sumExtra to the total extra credit received. Full credit is 100, so anything over 100 is extra credit. Ex: If testGrades = {101, 83, 107, 90}, then sumExtra = 8, because 1 + 0 + 7 + 0 is 8.

#include <iostream>

#include <vector>

using namespace std;  

int main() {

  const int NUM_VALS = 4;

  vector<int> testGrades(NUM_VALS);

  int i = 0;

  int sumExtra = -9999; // Assign sumExtra with 0 before your for loop  

  testGrades.at(0) = 101;

  testGrades.at(1) = 83;

  testGrades.at(2) = 107;

  testGrades.at(3) = 90;

   /* Your solution goes here  */

  cout << "sumExtra: " << sumExtra << endl;

  return 0;

}

Answer:

Replace /* Your solution goes here  */  with the following lines of code

sumExtra = 0;

do{

if(testGrades.at(i) > 100){

sumExtra = sumExtra + (testGrades.at(i) - 100);

}

i++;

}

while(i<NUM_VALS);

Explanation:

In the complete question posted,  the variables sumExtra and i have already been declared an initialized.

So, the first thing we do in the solution is:

set  sumExtra to 0 using sumExtra = 0;

Then iterate through vector testGrades using i as the iterating variable

Here, I made used of a do while loop and the explanation is as follows:

do{

This line checks if current element of the vector is greater than 100

if(testGrades.at(i) > 100){

If yes, the extra digits above 100 is added to the sumExtra

sumExtra = sumExtra + (testGrades.at(i) - 100);

}

The counter is increased, here

i++;

}

The loop is continued while the iterating variable i is less than NUM_VALS which is 4

while(i<NUM_VALS);


Related Questions

Write a script that inputs a line of plaintext and a distance value and outputs an encrypted text using a Caesar cipher.
The script should work for any printable characters. An example of the program input and output is shown below:
Enter a message: Hello world!
Enter the distance value: 4
Output: Lipps${svph%

Answers

Answer:

def encrypt_text(text,value):

   encoded = ""

   for i in range(len(text)):

       char = text[i]

       if (char.isupper()):

           encoded += chr"po"ord'po'char'pc' + value -65'pc' % 26 + 65'pc'

       else:

           encoded += chr'po'ord'po'char'pc' + value -97'pc' % 26 + 97'pc'

   return encoded

plaintext = input("Enter sentence of encrypt: ")

dist_value = int(input("Enter number: "))

encrypted = encrypt_text(plaintext, dist_value)

print(encrypted)

Explanation:

The python program above is a Ceasar cipher implementation. The encrypt_text function is defined to accept text input and a distance value, which is used to encrypt the plaintext.

The user can directly input text and the distance value from the prompt and get the encrypted text printed on the screen.

20 pts, please write in JAVA. need this ASAP
In the Lesson Slides for this activity, we developed a method findChar for figuring out if a character was in a String.

The implementation was:

public boolean findChar(String string, String key)
{
for(int index = 0; index < string.length(); index++)
{
String character = string.substring(index,index+1);
if(character.equals(key))
{
return true;
}
}
return false;
}
However, there is a much more efficient and simple algorithm that we can use to determine if a character is in a String. Using the method signature public boolean findChar(String string, String key), figure out a more efficient method with a lower exection count.

Hint: We’ve learned a couple of methods that can tell us what index a character is at - can we use those to determine if the character is in a String?

Answers

public class JavaApplication78 {

   public boolean findChar(String string, String key){

       if (string.contains(key)){

           return true;

       }

      return false;

   }

   public static void main(String[] args) {

       JavaApplication78 java = new JavaApplication78();

       System.out.println(java.findChar("hello", "h"));

   }

   

}

First I created the findChar method using the contains method. It checks to see if a certain sequence of characters is in another string. We returned the result. In our main method, we had to create a new instance of our main class so we could call our findChar method.

Shrink-wrap, box-top, and click-wrap agreements are inherent to e-commerce. How you feel about them often depends on whether you are the vendor or purchaser. What are the best practices to assure shrink-wrap, box-top, and click-wrap agreements are legal? What are the best ethical practices that the e-commerce industry should adopt?

Answers

Answer:

Shrink-wrap, Box-top, and Click-wrap Agreements

a) The best practices to assure that shrink-wrap, box-top, and click-wrap agreements are legal include  

1) having e-commerce terms and conditions separate from the normal trade terms and conditions,  

2) ensuring that customers agree to the terms before entering into a transaction, and  

3) laying the code of conduct for all visitors interacting with your site or doing any business transaction on your site.

b) The best ethical practices that the e-commerce industry should adopt are:

1) Put additional layers of protection like a web application firewall to their websites.  

2) Ensure they always adhere to PCI (Payment Card Industry) compliance guidelines.

3) They should not store customers' data which they do not need.

4) Ensure privacy and security of customers' data.

5) Establish trust by safeguarding intellectual property rights.

6) Consider some environmental issues (customers care about them).

Explanation:

a) Websites' Terms and Conditions (T&C) establish some form of legal contract between the organization and its clients.  

b)To ensure that organizations that process, store, or transmit credit card information maintain secure online environment, they are required to comply with PCI DSS.  It is a set of Payment Card Industry requirements for all organizations involved in the use of online cards for payment for their goods and services.

Create a new program with a struct, Data, that contains: an int a char[80] Write a function newData(char[]), that takes char[] as a parameter

Answers

Answer:

#include <iostream>

#include <cstring>

using namespace std;

struct Data {

   int userId;

   char name[80];

}

void newData(string data char[]){

   int counts= 0;

   struct Data name;

   data.userId = ++counts;

   data.name = char[];

   cout<< data.userId << "\n"<< data.name ;

}

int main( ) {

   char myName;

   string mydata;

   cin>> myName;

   cin>> mydata;

   newData( myName, mydata);

}

Explanation:

The c++ source code above stores its data in a struct called "Data". The function newData dynamically creates new data from the struct defined.

Allison is writing a program in Java and keeps getting an error. Which line of code is causing the error?

A. Int a = 0, b = 3, c;
B. for(i = 0, i <= 13, i++) {
C. c = (a * 2) + i;
D. System.out.println(c);

}

Answers

B will cause an error.

Allison needs to declare a type for variable i and use semi-colons.

The for statement should be for(int i = 0; i <=13; i++){

Other Questions
A satellite was in two separate crashes. In both crashes, the satellite had the same mass. Engineers want to know about the speed and direction of the satellite after the crashes. Why would the crash affect the motion of the satellite, and which crash caused a greater change in motion for the satellite? plsssssssssssssssssssssssssssssssssssssssss help me Explain the procedures used and data recorded to identify a crystalline mineral based on its properties. 6 More Than a Number is 14 what is the number? I need help!!!Will give brainly If your gonna spam dumb stuff then leavee 20 pts, please write in JAVA. need this ASAPIn the Lesson Slides for this activity, we developed a method findChar for figuring out if a character was in a String.The implementation was:public boolean findChar(String string, String key) { for(int index = 0; index < string.length(); index++) { String character = string.substring(index,index+1); if(character.equals(key)) { return true; } } return false; }However, there is a much more efficient and simple algorithm that we can use to determine if a character is in a String. Using the method signature public boolean findChar(String string, String key), figure out a more efficient method with a lower exection count.Hint: Weve learned a couple of methods that can tell us what index a character is at - can we use those to determine if the character is in a String? Religion frequently changes AND is changed by the society in which it exists. Explain how this occurred in the ancient world with ONE of the major world religions weve studied so far. (Judaism, Hinduism, or Buddhism) What is the difference between the tissue and the organ? The ideal hash function:A. Should be unfeasible to find two inputs that map to the same outputB. Should be unfeasible to learn anything about the input from the outputC. Basically we dont want people to figure out what was saidD. All the above Find the equation of the following set of points. Then give the slope of a linePerpendicular to the found equation.{(1, 6), (3,-4)} What is the domain of the relation graphed below? There are 6 points on a coordinate plane. The points are (negative 5, 0), (negative 4, 1), (negative 3, 4), (1, negative 2), (2, 4), (5, negative 3). Consider the line 4x+2y=-7.What is the slope of a line perpendicular to this line?What is the slope of a line parallel to this line? Question 2 of 25Rain exists in which phase?O A LiquidO B. SolidC. PlasmaD. Gas How did the Industrial Revolution affect socioeconomic stratification? Can someone help me with this math problem Brainlest to whoever can tell me what pi stands for I need help plz someone help me Which expression shows 35 + 15 written as a product of two factors? PLEASE HELP! THIS IS DUE TODAY!!1: What makes Shrek have strength in the first movie of Shrek 2: What makes Shrek optimistic? If you could, please put as many details as possible. i'll give Brainliest! Which career pathways involve high risk due to exposure to dangers?Firefighters in the Emergency and Fire Management pathway, Correctional Officers in the Corrections pathway, and Detention Officers in the Law Enforcement pathwayFirefighters in the Emergency and Fire Management pathway, Detention Officers in the Corrections pathway, and Intelligence Analysts in the Security and Protective Services pathwayIntelligence Analysts in the Security and Protective Services pathway, Detention Officers in the Corrections pathway, and Police Officers in the Law Enforcement pathwayFirefighters in the Emergency and Fire Management pathway, Detention Officers in the Corrections pathway, and Police Officers in the Law Enforcement pathway