Write a program that accepts as input, without prompts

Assignment Help C/C++ Programming
Reference no: EM13161489

Write a program that accepts as input, without prompts, a series of short values, terminated by end of file. The program outputs one line:


|val| pairs (without pipes)

Where |val| is the number of pairs of adjacent 1-bits in the sequence of bits formed by the collective shorts. This includes pairs where one bit is the rightmost in one short and the next is the leftmost in the following short.

Don't worry about error checking of the input. Assume it comprises zero or more integer values. Here's an example:

Test 1:
85 -2 -1

Output:
30 pairs

Those three shorts, in bit form, are as shown below, and there are 30 pairs of adjacent 1-bits in that bit sequence. Note that the last bit of one short may pair with the first bit of the next short.

0000000001010101 1111111111111110 1111111111111111

Some hints:

1. Plan carefully. There are many ways to do this; some are simpler than others. You should consider a couple of different ways before you dive in, or you may find yourself in a mess halfway through.

2. Remember that scanf returns EOF if it hits the end of file, and that signed integers do sign-extension if you rightshift.

3. Endian issues are not important since we're not writing binary data to file

For the files below, please obey the following rules: For file BitPairs.c: For entry space 1: a full programThe code must have complexity no higher than 122 per the standard complexity rules. Meeting this bar will get you 50% credit.You can get up to 100% total credit if you reduce the complexity further to 61.

Enter code for BitPairs.c

#include <stdio.h> #define BITS_PER_SHORT 16

Test Cases:

Test 1

Input Output
85 -2 -1
30 pairs

Results Summary: Not run yet
Test 2

Input Output
0 pairs

Results Summary: Not run yet
Test 3

Input Output
-20 42 20
11 pairs

 

 

Reference no: EM13161489

Questions Cloud

Which of the following could qualify as a top-down control : which of the following could qualify as a top-down control on a grassland community?
Research report by richard h. weindruch : In a research report by Richard H. Weindruch of the UCLA Medical School, it is claimed that mice with an average life span of 32 months will live to be about 40 months old when 40% of the calories in
Why is denaturation a problem : would elevation in body temperature effect lipids in the same way as denaturation? Why or why not?
State the reactants constant in a sn reaction : Suppose we doubled the volume of the solution (by adding more solvent) while keeping the quantities of the reactants constant in a SN1 reaction.
Write a program that accepts as input, without prompts : Write a program that accepts as input, without prompts, a series of short values, terminated by end of file. The program outputs one line:
Jrp a superior way to discover requirements : What makes JRP a superior way to discover requirements as compared to a regular company meeting? What do you think is the most important aspect of a JRP meeting
How would you determine which were important : What factors might these types of stores have in common behind their declines? How would you determine which were important and which were not?
Why is a oil spill so dangerous : How would it harm a land environment like a park or a forest?
Describe how the popsicle stick looks and feels : Now take a popsicle stick and dip it into the water and oil to represent a marine animal accidentally swimming througfh an oil spill.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Using opengl to create a cube

Write a program in C/C++ using OpenGL to create (without using built in function) a cube by implementing translation algorithm by translating along 1. X-axis, 2.Y-axis and 3. X and Y plane

  You will create a linked list module

You will create a linked list module that exactly meets the specifications given in the supplied header (.h) file. The playlist program must accept a filename on the command line (argv).

  Write c program that forks two child processes

Write a C program that forks two child processes. The parent process will print all prime numbers up to 229, the first child process will print the first 50 Fibonacci numbers.

  Write function to accept character array

Write down the C++ function which will accept the character array of at most 30 cells. Your function must return true if string and its reverse are identical;

  Program to produce ten random permutations of numbers

In C++(must be able to compile in Visual Studio ): Write a program to produce ten random permutations of numbers 1 to 10.

  Give students practice in writing and calling their function

To give students practice in writing and calling their own functions. To give students practice in implementing and planning complex programs.

  Implement database having array of pointers

One way to implement this database is to have an array of pointers pointing to Employee objects. You will obviously require a function named Calculate_salary() which will be different for each employee class. Write code in c++

  Design a simple game of blackjack

Prepare a simple game of blackjack using object oriented programming.

  Program that asks the user to enter up to 100 integer score

Write a C program that asks the user to enter up to 100 integer scores, which are to be stored in an array. (You should allow the user to terminate input prior to entering all 100 scores.) The program should then display all the scores, ten per line,..

  Write c program to find smallest-largest values

Write a program c that will find the smallest, largest and average values in a collection of N numbers.Get the value of N before scanning each value in the collection of N numbers.

  Prepare a businesspartner

Prepare a BusinessPartner class that contains a company name, first name and a telephone number.

  Loops and if conditions

Write a program that requests a password

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