Question

Computer Security question Suppose you have two integer variables a and b and wish to check...

Computer Security question

Suppose you have two integer variables a and b and wish to check if their multiplication will lead to an overflow. Write code below in C++ to check to see if the multiplication is safe (if it is unsafe, exit(-1) ). You have as a constant MAX_INT to work with.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

#include<cstdlib>

using namespace std;

int main(){

int a,b,c;

c=0;

for(int i=0;c<=MAX_INT && i<b;i++)

c=a+c;

if(i!=b)

cout<<"Exit -1";

else

cout<<"Sucessful";

return 0;

}

Add a comment
Know the answer?
Add Answer to:
Computer Security question Suppose you have two integer variables a and b and wish to check...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The following variables have been declared and assigned values: integer a = 10, integer b =...

    The following variables have been declared and assigned values: integer a = 10, integer b = 2, float c =4.0, float d=3.0. State the value of the variable after each statement is executed. Part a: c = a / b + d / b – (b – a)                                    c =__________________                   Part b: a = (b > a)                                                         a =__________________ Part c: d = d + b                                                            d =__________________ Part d: a = b / d + a + b /...

  • 1. Assume you have a Car class that declares two private instance variables, make and model....

    1. Assume you have a Car class that declares two private instance variables, make and model. Write Java code that implements a two-parameter constructor that instantiates a Car object and initializes both of its instance variables. 2. Logically, the make and model attributes of each Car object should not change in the life of that object. a. Write Java code that declares constant make and model attributes that cannot be changed after they are initialized by a constructor. Configure your...

  • Suppose we have two integer arrays with the same type, write an AL program to check...

    Suppose we have two integer arrays with the same type, write an AL program to check whether or not there are two integers, one from each array, with sum equal to zero. If there are such integers exist, print out all such combinations to the console window, otherise, print out "No integers in these two arrays, one from each array, with sum equal to zero." to the console window. December 3. 2018 For example, suppose we have the following two...

  • Question Two a) Suppose that you have an extra K111.3 today that you wish to invest...

    Question Two a) Suppose that you have an extra K111.3 today that you wish to invest for one year. If you can earn 11.1% per year on your investment, how much will you have in one year?                                                                                                      (10 marks) 1.) Compared to investing in a single security, how does diversification help the investors?                                                                                   (3 marks) 2) In what situation is Portfolio diversification least likely to protect against losses: 3) Explain the features of a defined contribution pension plan: (5...

  • Question 16.3.6: (Introduction to Algorithms 3rd Edition) Suppose you have an optimal prefix code on a...

    Question 16.3.6: (Introduction to Algorithms 3rd Edition) Suppose you have an optimal prefix code on a set C = { c0, c1, …, c(n-1) } of characters and you wish to transmit this code using as few bits as possible. Write an algorithm to represent any optimal prefix code on C using only 2n-1+n*⎡lgn⎤bits. (Hint: Use 2n-1 bits to specify the structure of the tree, as discovered by a walk of the tree.)

  • 1. Suppose you were to collect data for each pair of variables below. You wish to make a scatter plot. Decide which wou...

    1. Suppose you were to collect data for each pair of variables below. You wish to make a scatter plot. Decide which would be better suited for the explanatory variable and the response variable. Explain your choice b. Discuss the direction, form and strength you would expect to see. a. i. College freshman: shoe size and grade point average. Apples: circumference (inches) and weight (ounces). When climbing a mountain: altitude and temperature iv. Drivers: Blood alcohol level, reaction time People:...

  • Question (c) Suppose you have two jointly distributed random variables, X and Y. Suppose you know...

    Question (c) Suppose you have two jointly distributed random variables, X and Y. Suppose you know the following facts. • Var(–7.5 X) = 53.2925 • Var(1.5 x Y) = 1.01765 • Var(2 x X +3 + Y) = 6.26319 i. What is Cov(X,Y)? ii. What is the correlation of X and Y? iii. If you had a random sample of observations of x and y and estimated the regression Y = Bo + BiX +€ What would the

  • For Computer Organization and Design: Suppose we have 3 arrays A, B, and C, array A’s...

    For Computer Organization and Design: Suppose we have 3 arrays A, B, and C, array A’s base address is in $S3, B’s base address is in $S4, C’s base address is in $S5. You can only use two temporal registers $t0 and $t1. Convert the following code into MIPS assembly language code. Suppose every array element occupies 1 word in MIPS (32 bits). A[20] = B[0] + C[6] - 1

  • Could someone check my work and make sure the units are right thank you Suppose you...

    Could someone check my work and make sure the units are right thank you Suppose you wish to see if there is a relationship between the price (in $100) and rating (in points) of 7 laptop computers tested by Consumer Reports. You collected the information below. (See exercise 11 on page 614 of your textbook for a similar problem.) SS = SS= MSE = 42.2143 79.5714 18.5739 Question 1 Using the Ftable, find the p-value for the Global Fstat. 0.025...

  • 5. Suppose we have two random variables X and Y. They are discrete and have the...

    5. Suppose we have two random variables X and Y. They are discrete and have the exact same distribution and also independent. You see below the distribution of X which of course also the distribution of Y as well, that is what we called independent and identically distributed) P(X =- X. Remem- a./ (-) Find and draw the cumulative distribution function F() function of ber that F(x) -P(X S) HINT: For the next 3 parts you might want to make...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT