C++ :: Program That Reads In A Sequence Of Binary Digits?

May 11, 2013

c++ program that reads in a sequence of binary digits (values 0 and 1) and stores them into a STL container. The input should terminate on any input that is not a 0 or 1. After finishing the read-process, apply a "bit-stuffing" algorithm to the container. In this case the bit stuffing should occur after four consecutive bits of the same value.i,e. four 0's or four 1's.. Also write the de-stuffing code to process the stuffed data to recreate the original data and verify that the original data is recovered correctly.

View 6 Replies


ADVERTISEMENT

C :: Program That Reads Number Of Digits From File?

Jan 16, 2014

I've been working on a program that displays the number of digits in each line of a file, but I feel stuck. Take for example a file that contains these characters:

6347aaa9
54j
811111
6a
709

And I'm trying to display a result like this

1 //that's the number of the line 5 //the number of digits
2 2
3 6
4 1
5 3

Here's what I've written so far:

Code:
#include<stdio.h>
int main() {
char a=0;
int number_of_digits=0, linescount=0, num, number_of_digits_per_line=0;
FILE *inputFile;
if(!(inputFile=fopen("C:TestTest.txt","r")))

[Code]..

I also thought of using fgets and strlen but I am not very good with them and couldn't get the program to work correctly. It did work but it displayed all characters, letters included, not only digits.

View 2 Replies View Related

C++ :: Reads In Two Positive Integers That Are 20 Or Fewer Digits In Length - Output Sum?

May 1, 2013

Write a C++ program that reads in two positive integers that are 20 or fewer digits in length and outputs the sum of the two numbers.

Your program will read the digits as values of type char so that the number 1234 is read as four characters '1', '2', '3' and '4'. After they are read into the program, the characters are changed to values of type int. The digits will be read into a partially filled array and you might find it useful to reverse the order of the elements in the array after array is filled with data from the keyboard.

Your program will perform the addition by implementing the usual pencil and paper addition algorithm. The result of the addition is stored in an array of size 20 and the result is written to screen. if the result of the addition is an integer with more than maximum number of digits(that is more than 20 digits) then your program should issue a message saying that it has encountered "integer overflow".

You should be able to change the maximum length of the integers by changing only one globally defined constant. Include the loop that allows the user to continue to do more additions until the user says the program should end.

For some reason the sum won't add or output though, This is what i have so far:

#include <iostream>
using namespace std;
const int MAXIMUM_DIGITS = 20;
void input_Large_Int (int a[], int& size_of_A); //input function for the two big integers
void output_Large_Int(int a[], int size_of_A); //output function for the two big integers and the sum integer
void add(int a[], int size_of_A, int b[], int size_of_B, int sum[], int & size_Sum); //add function for the big integers' sum

[Code] .....

View 1 Replies View Related

C++ :: Converting Binary Digits To Hex?

Apr 16, 2013

converting 8bit binary into 2 digit hex

how to do this?

im starting it now but going in the direction of using arrays

View 4 Replies View Related

C++ :: Binary Search Algorithm - Find Sum Of Used Number In Sequence

Mar 27, 2014

I have to made a programme which will search for given number and it must work in O(log(n)). The problem is that this programme beside finding this number have to find how many times this given number is used in this sequence.

Sequence is from lowest to highest only one possibility to use binary search algorithm

For example when we have squence
-1 -2 3 3 3 3 4 5 6 7 7 8 9 9 9 9 10

The numbers we need to search are
1 , 3 , 7 , 9 , 11 , 12

The answer is
0 , 4 , 2 , 4 , 0 , 0

So we need to find the sum of used number in sequence.

I have written algorithm Code: int start = 0;
int end = sequencelenght - 1;
int mid = 0;
/// Binary serach
while (start<=end) {
int mid=(start+end)/2;
if (sequence[mid]==givennumber) {

[Code] .....

As u see i search for given numer with binary with O(log(n)) but when i have to sum the duplicates the only good way i see is using loop to right and left but this have got log(n) specification (because when sequence would be for example 7 7 7 7 7 7 7 7 7 and given number to search will be 7 this will be O(n) loop).

How would look the most optimal algorithm look for this exercise? I mean O(log(n)) the fastest algorithm....

View 6 Replies View Related

C/C++ :: Program That Reads A File?

Jan 21, 2015

I wrote the following program:

#include "stdafx.h"
#include "string.h"
#include "ctype.h"

[Code].....

View 1 Replies View Related

C++ :: Program That Reads In Ten Whole Numbers And Output Sum

Jan 23, 2014

Write a program that reads in ten whole numbers and that output the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the ten numbers just once each and the user can enter them in any order.

Your program should not ask the user to enter the positive numbers and the negative numbers separately. Assume the user will type integer numbers.

this is what i got but it wont run saying there is an error

#include<iostream>;
using namespace std;
int main() {
int count=0;
int num;
int positive=0;
int negative=0;

[Code] ....

View 5 Replies View Related

C/C++ :: A Program That Repeatedly Reads In Values?

Sep 26, 2014

I started to write a program that repeatedly reads in values for a,b and c and find the root of the polynomial

ax^2 + bx + c = 0

The program should print out for example:

two complex roots: root1 = -1.00000 + i*1.41421
root2 = -1.00000 - i*1.41421

My code:

#include <stdio.h>
#include <math.h>
int main(void){
int a,b,c;
printf("Choose the values of a, b and c for the equation ax^2 + bx + c");
scanf("%d%d%d
",a,b,c);

[code].....

View 6 Replies View Related

C++ :: Input Integer Then Output Both Individual Digits Of The Number And Sum Of Digits

Oct 11, 2014

My problem needs to prompt the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. An example would be entering 8030 and it spits out 8 0 3 0 as well as 8+0+3+0=11 and it needs to work with negative numbers.

Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int base;

[Code] ....

Now I don't know if any of this is right a hint my professor gave us is that to get the fourth digit you would do base mod 10 and to get the first digit you do base divided 1000...

Code:

{
int power;
int counter=0;
int value=1;
cout << "Enter the power of 10 you want: ";

[Code] ....

View 2 Replies View Related

C++ :: Write A Program That Reads Data From A File?

Feb 26, 2013

Write a program that reads data from a file (use the attached data file). These data are a student name and 3 test scores. The program should calculate the average of the 3 test scores, and display the name, 3 test scores, and the average to the monitor.

Useful tips:
a) Include the following header files: iostream, fstream, iomanip, and string
b) The name of the data file is “datafile.txt”, you need to save the file in the same folder of the source file.
c) use the manipulators (setw, setprecision, setfill, showpoint, fixed) to format the average with 1 digits after decimal point as following.
d) Use character ‘ ’ for tab.

View 3 Replies View Related

C++ :: Write Program That Reads Group Of Chars?

Nov 28, 2014

Write a program that reads a group of chars till $. Then, compute # of vowels, # of digits, # of word and # of special chars. Your program should display all required results.

So in what way should I do it? Loop, array, ...?

View 13 Replies View Related

C/C++ :: Program That Reads 3-by-4 Matrix And Displays Sum Of Columns

Nov 18, 2014

I'm not sure why Im getting a wrong Sum. of the Columns.

Write a method that returns the sum of all the elements in a specific column in a matrix using the following header:

double sumColumn(const double m[] [SIZE], int rowSize, int columnIndex)

Write a test program that reads a 3-by-4 matrix and displays the sum of each column. here is a sample run:

Enter a 3-by-4 matrix row by row:
1.5 2 3 4
5.5 6 7 8
9.5 1 3 1
Sum of the elements at column 0 is 16.5
Sum of the elements at column 1 is 9.0
Sum of the elements at column 2 is 13.0
Sum of the elements at column 3 is 13.0

#include <iostream>
using namespace std;
const int SIZE = 4;
int rowSize=3;

[Code].....

View 1 Replies View Related

C :: Using Arrays - Program That Prompts For And Reads In Test Scores

Feb 11, 2013

Write a program that prompts for and reads in test scores. You may assume that valid test scores will be integer values between 0 and 100. You may also assume that the user will not enter more than 35 test scores. Use a preprocessor directive to define this value. User input will be complete when the user enters a -1 for the test score. When all of the test scores have been entered, the program will print out the scores. Use a while or do-while loop to read in the values. Use a for loop to print out the values.

Sample output:
Enter test score 1: 88
Enter test score 2: 67
Enter test score 3: 74
Enter test score 4: 94
Enter test score 5: 79
Enter test score 6: 56
Enter test score 7: -1
Number of scores entered: 6
Test scores entered : 88 67 74 94 79 56

View 14 Replies View Related

C :: Program That Reads In TXT File And Searches Through Text For Keyword?

Nov 8, 2014

I'm working on a program that reads in a .txt file and searches through the text for a keyword. If it gets a hit on the keyword, the line number where the keyword is located and the line that contains the keyword is printed out. What I have now doesn't catch every occurance of the keyword "a".

Code:

#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {

[Code]......

View 4 Replies View Related

C++ ::  program That Reads Into String Object A Name With Three Blanks Between First And Last Names

Oct 4, 2014

" Write a program that reads into a string object a name with three blanks between the first and last names. Then extract the first and last names and store them in separate string objects. Write a function subprogram that displays its string argument two times. Call this function display the first name for times and then to display the last name six times."

I completed coding the first part of this task with the strings and combining strings together. However, i have having trouble with the other half of this task. It begins from "Write a function subprogram to display the last name six times." This is where i have so far --

#include <iostream>
#include <string>
using namespace std;
int main()
{
// Defining the strings

string firstname, lastname;
string wholename;
string greet = " Hi ";

[code]....

View 2 Replies View Related

C++ :: Write Program For Class That Reads From Input File?

Mar 7, 2013

I am trying to write a program for class that reads from an input file the month, year & total collected. I am using notepad for the input file.

This is what the notepad file looks like
-----------------------------------
March 2013 63924.62

Why does it give me random numbers in the output rather than what the notepad has?

Also, the outfile is completely blank.

#include <iostream>
#include <iomanip>
#include <fstream>

[Code].....

View 2 Replies View Related

C/C++ :: Program That Reads Data From A Text Document And Allows To Modify

Apr 30, 2015

I'm trying to make a program that reads data from a text document and allows me to modify it. I am stuck with the display() function. I can get the printf statement to display all my array values except the char AD value. When I include flight[i].AD it causes the program to crash. When I run the program to only display the AD variable I get a bunch of weird symbols. I'm not sure where the program is going wrong because it seems to be storing values properly except for the AD variable.

#include <fstream>
using namespace std;
//named constants
const int MAX=100; //maximum flights
const int SIZE=20; //maximum characters
//struct definition
struct FlightType
{
char name[SIZE];

[Code]...

View 1 Replies View Related

C++ :: Program Which Reads TIFF Files And Shows Header

Dec 13, 2013

I have program which reads tiff files, and shows header.

Code:

#include <iostream>
#include <fstream>
using namespace std;
#define II 1
#define MM 2
typedef struct {
short unsigned byte_order;

[Code] ....

but I have a problem, my program doesn't shows:

ImageWidth
ImageLength
XResolution
YResolution

I must do this, without using another library like libtiff...

View 1 Replies View Related

C/C++ :: How To Do Fibonacci Sequence Program

May 5, 2014

Q) How to do nested loops?
Q) How to do Array?
Q) How to do Fibonacci sequence?

View 1 Replies View Related

C :: Program That Reads Alphanumeric Characters And Computes Average ASCII Value

Feb 16, 2015

Write a program that reads alphanumeric characters from the keyboard, and computes the average ascii value of the alpha numeric characters, the average alphabetical character, the average numeric character and the average uppercase character. Outputting each, you program should terminate reading once it read a non-alphanumeric character.

Here's what i have so far.

Code:
#include <stdio.h>
#include <ctype.h>
int main(void) {
int value = 'a';
int digit_loop = 0;
int alpha_loop = 0;
int upper_loop = 0;

[Code] ....

View 7 Replies View Related

C++ :: Create A Program That Reads Numbers And Calculate Them On A Separated Subroutine

Nov 15, 2013

I need to create a program that reads some numbers, and calculate them on a separated subroutine, and the return of this subroutine must be the sum of all the numbers. I'm getting an error but I can't figure out why =/

#include <iostream>
using namespace std;
int calc(int val, int qtd){
int sum=0;
for (int cont=0; cont<qtd; cont++)
sum=sum+val;
return sum;

[Code]...

The error that I'm getting is on the line 22.

The error message: "invalid conversion from 'int*' to 'int' [fpermissive]

View 4 Replies View Related

C++ :: Use Class Structure To Create Program That Reads In Two Rational Numbers?

Nov 4, 2013

how to use a Class structure to create a program that reads in two rational numbers and adds them, subtracts, multiplies, and divides them.

View 3 Replies View Related

C/C++ :: Login Program That Reads Username And Password From Text File

Feb 14, 2015

I am trying to make a simple login program that reads username and password from a text file.

In my text file I have:

name1;pass1
name2;pass2
name3;pass3
name4;pass4
name5;pass5

Everything is working okay with name1 and pass1, but if I try to log in with different credentials, for example name2 and pass2 it says "invalid details"

Here is my code:

string user, chuser;
string pass, chpass;
string los;
ifstream loginData("logindata.txt");
cout << "Please type in your username:" << endl;
getline(cin, user);

[code].....

View 5 Replies View Related

Visual C++ :: Program That Reads Numbers From A File And Calculates Average

Mar 13, 2014

[URL] .....

Here is my code and basically these are the steps. I feel like we have something good to work on but we keep getting errors.

a. Data to the program is input from a file of an unspecified length; that is, the program does not know in advance how many numbers are in the file.

b. Save the output of the program in a file.

c. Modify the function getNumber so that it reads a number from the input file (opened in the function main), outputs the number to the output file (opened in the function main), and sends
the number read to the function main. Print only 10 numbers per line.

d. Have the program find the sum and average of the numbers.

e. Modify the function printResult so that it outputs the final results to the output file (opened in the function main). Other than outputting the appropriate counts, this new definition of the function printResult should also output the sum and average of the numbers.

View 12 Replies View Related

C++ :: Getting Longest Sequence In Hailstone Program

Oct 4, 2014

The following is a part of a hailstone cpp program. I want to write an option to let users enter 2 numbers and the program evaluates the longest sequence the number has within the 2-number range and return the count.

Code:
int longestHailstoneSequenceLength(int start, int end)
{
int max = 0;
int s= start;
while (s!=1)

[Code] ....

View 8 Replies View Related

C++ :: Program That Reads Text From A File And Outputs Each Line To The Screen - I/O Streams

Jun 15, 2013

I seem to be missing a concept or 2 here ... I am tasked with writing a program that reads text from a file and outputs each line to the screen as well as to another file PRECEDED by a line number ...

In addition, I have to Print the line number at the start of the line and right-adjusted in a field of 3 spaces ...

Follow the line number with a colon then 1 space, then the text of the line.

Another kicker, is I have to grab the data 1 character at a time and write code to ignore leading blanks on each line.

Here is what I have so far:

#include <iostream>
#include <conio.h>
#include <fstream>
#include <string>
#include <cstdlib>
#include <cctype>
using namespace std;
int main() {
char next;
int count = 0;

[Code] ....

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved