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

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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