Question

HALIX PROGRAMMING C++ 1. Write Halix machine code to read and add 5 values. Test cases:...

HALIX PROGRAMMING C++

1. Write Halix machine code to read and add 5 values.

Test cases: 1 2 3 4 5 ==>15 -1 -2 -3 -4 23 ==> 13 0 0 0 0 0 ==> 0

2. Write Halix machine code to read a value: Double it if the nu halve it when it's odd.

Test cases: 14 ==> 28 0 ==>0 25==>12 -2==>-4 -7==>-3

3. Write a program that reads ans echoes (display what was just values that are terminated by the value 777.

Pseudo Code: int val;

cin >> val;

while (val != 777)

{

cout > val;

cin >> val;

} cout << 4444;

Test cases: 1 2 777 ==> 1 2 4444 777 => 4444 25 777 ==> 25 4444 -2 7 9 4 3 84 777 ==> -2 7 9 4 3 84 4444

4. Write a program that reads input values terminated by the value 9999, and computes the product of the negative values, and the sum of the positive value.

Pseudo-code: int val, negProd=1, posSum=0;

cin >> val;

while (val != 9999)

{

if (val < 0)

negProd *= val;

else

posSum += val;

cin >> val;

}

cout << posSum << negProd;

cout << 5555

Test cases: 1 2 9999 ==> 1 3 9999=>1 0 1 -2 2 -5 -5 ==> 40 3

1 -2 2 -5 -5 ==> -40 3 -2 7 9 4 3 -84 9999 ==>168 23

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

1.

#include <iostream>
using namespace std;
int main(){
int a, b, c, d, e;

cout << "Enter Five numberes ";
cin >> a >> b >> c >> d >> e ;

c = a + b + c + d + e;
cout <<"Sum of the numbers: " << c << endl;

return 0;
}

2.

#include <iostream>
using namespace std;
int main(){
int n,res;
cout << "Enter Number: ";
cin >> n;

if ( n % 2 == 0){
   res = n*2;
cout << res ;
   }else{
   res = n/2;
cout << res;
   }
return 0;
}

3.

#include <iostream>
using namespace std;
int main(){
int n,res;
   cout<<"Enter numbers ";
   while(1){ //While 1 is always Ture
       cin >> n;
       if (n==777){
           break;
       }else{
           cout << n <<" " ;
       }
   }
   cout<<"4444 ";
return 0;
}

4.

#include <iostream>
using namespace std;
int main(){
int n,neg_product=1,pos_sum=0;
   cout<<"Enter numbers ";
   while(1){ //While 1 is always Ture
       cin >> n;
       if (n==9999){
           break;
       }else if (n>0){
           pos_sum +=n;
       }else if (n<0){
           neg_product *=n;
       }
   }
   cout<< neg_product << " "<< pos_sum;
return 0;
}

I give the screenshot of code also.

Thank You :-)

Add a comment
Know the answer?
Add Answer to:
HALIX PROGRAMMING C++ 1. Write Halix machine code to read and add 5 values. Test cases:...
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
  • C++ programming I need at least three test cases for the program and at least one...

    C++ programming I need at least three test cases for the program and at least one test has to pass #include <iostream> #include <string> #include <cmath> #include <iomanip> using namespace std; void temperatureCoverter(float cel){ float f = ((cel*9.0)/5.0)+32; cout <<cel<<"C is equivalent to "<<round(f)<<"F"<<endl; } void distanceConverter(float km){ float miles = km * 0.6; cout<<km<<" km is equivalent to "<<fixed<<setprecision(2)<<miles<<" miles"<<endl; } void weightConverter(float kg){ float pounds=kg*2.2; cout<<kg<<" kg is equivalent to "<<fixed<<setprecision(1)<<pounds<<" pounds"<<endl; } int main() { string country;...

  • Write the pseudo code using modules for the following questions 1.) write pseudo code for a...

    Write the pseudo code using modules for the following questions 1.) write pseudo code for a program that outputs every number from 1 through 20 along with their values doubled and tripled 2.) write pseudo code for a program that outputs every number in reverse order from 25 down to 0

  • C++ Write a function so that the main() code below can be replaced by the simpler...

    C++ Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). Original main(): int main() { double milesPerHour; double minutesTraveled; double hoursTraveled; double milesTraveled; cin >> milesPerHour; cin >> minutesTraveled; hoursTraveled = minutesTraveled / 60.0; milesTraveled = hoursTraveled * milesPerHour; cout << "Miles: " << milesTraveled << endl; return 0; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include <iostream> using...

  • Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a...

    Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a class Employee (with member variables: char * name, int id, and double age). 2. Create a constructor that should be able to take arguments and initialize the member variables. 3. Create a copy constructor for employee class to ensure deep copy. 4. Create a destructor and de allocate the dynamic memory. 5. Overload the assignment operator to prevent shallow copy and ensure deep copy....

  • C programming! Write a program that reads integers until 0 and prints the sum of values...

    C programming! Write a program that reads integers until 0 and prints the sum of values on odd positions minus the sum of values on even positions. Let ?1, ?2, … , ??, 0 be the input sequence. Then the program prints the value of ?1 − ?2 + ?3 − ?4 + ⋯ ??. The input is a sequence of integers that always contains at least 0 and the output will be a single number. For example, for input...

  • Question 1 Given the following composite condition (a>=0 && b==3) || c>b Generate a...

    Question 1 Given the following composite condition (a>=0 && b==3) || c>b Generate a set of test cases (just the input values for a, b, and c) that you need to have 100% MC/DC coverage. Question 2 Given the following fragment of code: int tent=0, x=92, num; cout<<"Guess the number :"; cin>>num; while ((tent<5)&&(num!=x)) { tent++; if (num>x) cout<<"Smaller\n"; else if (num cout<<"Bigger\n"; else cout<<”You won!\n” cout<<"Guess the number :"; cin>>num; } (1) Build the corresponding control flow graph. (2)...

  • c++, we have to write functions for the code given below and other instructions for it...

    c++, we have to write functions for the code given below and other instructions for it to compile. I am having issues understanding how to confront the problem and how to write functions and read the program so it can eventually be solved so it can be compiled 7/ * INSTRUCTIONS: Write two functions in the space // * indicated below. // * // * #1 => Find index of maximum value: Write a function that will // * find...

  • Write a C++ program to read in 4 different types of data values using cin, cout,...

    Write a C++ program to read in 4 different types of data values using cin, cout, and the getline() function and display the values in the same order to the screen. Use cin to read in the first value and getline() to read in the remaining characters. Note that the 4 data items are entered on 1 line. The following shows a sample run of the program. Enter 4 data values: 45 abc 12.34 d The 4 data values entered...

  • 1. Please provide a C++ program which faithfully reads a list of non-negative integer scores, ultimately...

    1. Please provide a C++ program which faithfully reads a list of non-negative integer scores, ultimately terminating the list reading when the sentinel value (lets use -9999) is entered. The program should then correctly report the number of non-negative scores entered and the arithmetic mean (average) of those scores 2. Demonstrate your programs behavior in response to errors on input (that is, show that it faithfully rejects improper input such as alphabetic characters, decimal points, and commas). Here are some...

  • Question 1 Let's consider the following code * * * * Compile and fix all errors No test cases are...

    Please answer in C++ ONLY, and please fill all comments elaboratively. Question 1 Let's consider the following code * * * * Compile and fix all errors No test cases are required for this question. Run and provide a single screenshot showing the output. Complete the missing comments to explain the action performed by each statement highlighted in red. The first comment is given as an example. Copy and paste the source code with the comments filled out in your...

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
ADVERTISEMENT