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 a program for a company named retail-mart

Prompt the user to enter an item name (one word only), a quantity and a price. For this step, in addition to functionality, I'll be looking at: location of the variable declarations; appropriateness of data types selected; appropriateness of the va..

  Write a program to read a data file and extract parameters

Write a C/C++ program to read a data file and extract parameters. The program must obtain the filename via a command-line argument.

  C program to compute parking fare for customers

Write C program to compute parking fare for customers who park their cars in parking lot when following information is provided: A character showing type of vehicle: C for car, B for bus and T for truck

  Implement a graphics system that has classes

Implement a graphics System that has classes for various figures: rectangles, squares, triangles and circles. A rectangle has data members height, width, color , and center point. A square has center point and an edge and color

  Determine the meaof the numbers in the array

Determine the mean(average) of the numbers in the array, and output the reslt. Use a subprogram to input the numbers, a function to find the mean.

  Create class integerset

Create class IntegerSet for which each object can hold integers in the range 0 through 100. Represent the set internally as a vector of bool values. Element a[i] is true if integer i is in the set. Element a[j] is false if integer j is not in the set..

  Struct complex

A complex number can be represented by two parts, real and image. A series complex data can be organized as a group of elements by linked list, which is shown as below: struct Complex

  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;

  Create a template class

Create a template class, SVector, that implements a constructor

  rewrite that statement in a more readable style.

Give an example statement in C, C++, or Java that is particularly unreadable. Rewrite that statement in a more readable style.

  Program to generate 100,000 prime numbers

Write a POSIX C/C++ program to generate 100,000 prime numbers. Assume that the program will be run on a computer with 5 CPUs and that your goal is to have this program finish as quickly as possible.

  C assignment of curl library

C Assignment Curl library must be used To be done on linux, it should be compiled using the following command: gcc -Wall -ansi -pedantic NameOfFile.c -lncurses Please make sure it is commented with clarification Variable names in camel case

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