Question about Compilers & Programming Tools

1 Answer

Please Solve this C++ Program

Convert a string into binary and count number of 3 consecutive ones present in it and print it .

Note : Don't use temporary integer array variable to store the binary code




Posted by on

1 Answer

  • Level 1:

    An expert who has achieved level 1.

  • Contributor
  • 1 Answer

Write a program to prompt the user to input several lines of input. A line of inputs is terminated by '*'. For each readline of input the program should output:(use pointer notation for the array) . The total # of words . The lenght of the longest word in the line At the end the program should output: . The total number of words read in all lines of input . The lenght of the longest word read in all lines of input

Posted on Jun 10, 2009

Add Your Answer

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

1 Answer

How to write a program to translate english text to binary string and write a program to do inverse 27 = . , 28 = , 29= ? 30 = . 31=


to convert from text to binary, you would do something along the following lines..
1. have the user enter a string.
2. loop through the string (for each char in stringEntered..)
3. convert the character to binary using the methods provided to you by your language of choice

For the reverse (binary to text):
you must take 8 bits of data (which would be a single character), and convert it to text using the methods provided by your language of choice..

here's some links that might be of interest to you.
Visual FoxPro VFP CTOBIN and BINTOC Functions Equivalent In Net The Most Accurate and Reliable Source Code Converters

Feb 06, 2015 | Microsoft Visual Studio 6 6.0 Professional...

1 Answer

Divide the word Dangerous into syllabes


(sounds like a school assignment to me) ;-)

-count (& save) the 3 characters (1st syllable).
-start at position 4 (3+1 chars) in the string.
-count (& save) the 3 characters (2nd syllable).
-start at position 7 (6+1 chars) in the string.
-count (& save) the 3 characters (3rd syllable).

Logic:

-Initialize syllable-counter (x) to 1, position-counter to 1 (z).
-Initialize syl(x) strings to Null, where x = 1 to 3.
-Assign "dangerous" to string variable.

z = 1
y = 1
x = 1
string = "DANGEROUS"

For x = 1 to 3 DO
*Comment. read 3 chars (in a loop), add them to Syl (x).
For y = 1 to 3 DO
read a char(y) from the string at position-counter(z)
syl(x) = syl(x) + char(y)
z = z + 1
END DO
END DO


NOTE: not 100%, but close.

May 13, 2014 | Compilers & Programming Tools

1 Answer

Wirte a pogram in java using for loop,that will print out the first 1 numbers of a fibonacii series that is:1 1 2 3 5 13 21 34 55


package com.gpt;

import javax.swing.JOptionPane;

/*
This program computes Fibonacci numbers using a recursive
method.
*/
public class Fibonacci
{
public static void main(String[] args)
{
String input = JOptionPane.showInputDialog("Enter n: ");
int n = Integer.parseInt(input);

for (int i = 1; i {
int f = fib(i);
System.out.println("fib(" + i + ") = " + f);
}
System.exit(0);

}

/**
Computes a Fibonacci number.
@param n an integer
@return the nth Fibonacci number
*/
public static int fib(int n)
{
if (n return 1;
else
return fib(n - 1) + fib(n - 2);
}
}

Feb 24, 2011 | Sun Java Programming Language (cdj-275)

3 Answers

A java code for anagram


import java.io.IOException;

public class AnagramApp {
static int size;

static int count;

static char[] charArray;

public static void main(String[] args) throws IOException {
String input = "Java Source and Support";
size = input.length();
count = 0;
charArray = new char[size];
for (int j = 0; j < size; j++)
charArray[j] = input.charAt(j);
doAnagram(size);
}

public static void doAnagram(int newSize) {
int limit;
if (newSize == 1) // if too small, return;
return;
// for each position,
for (int i = 0; i < newSize; i++) {
doAnagram(newSize - 1); // anagram remaining
if (newSize == 2) // if innermost,
display();
rotate(newSize); // rotate word
}
}

// rotate left all chars from position to end
public static void rotate(int newSize) {
int i;
int position = size - newSize;
// save first letter
char temp = charArray[position];
//shift others left
for (i = position + 1; i < size; i++)
charArray[i - 1] = charArray[i];
//put first on right
charArray[i - 1] = temp;
}

public static void display() {
System.out.print(++count + " ");
for (int i = 0; i < size; i++)
System.out.print(charArray[i]);
System.out.println();
}
}

Nov 22, 2010 | Compilers & Programming Tools

1 Answer

Twenty-five numbers are entered from the keyboard into an array.The number to be searched is entered through the keyboard by user.Write a program to find if the number to be searched is present in the...


pseudo is
-> integer type count =0;
->Take input from user 'Number'
->loop from 0th to 24th element
->Compare each element with user entered number and if it matches then do count++.
finally display the count.

Jul 29, 2010 | Advanced Graphics Programming Using OpenGL...

1 Answer

Design the program 3 grades output the grades according to each rank


#include <string>
#include <fstream>

#define MAX_NUM_STUDENTS 15
#define MAX_LEN_NAME 20
#define LEN_SSN 10

enum Rank {Freshment, Sofomore, Junior, Senior};
enum letGrade {A, B, C, D, F};

class StuRecord {
public:
void ReadRecord(ifstream& inputFile);
// Precondition:
// Input stream inputfile is opened and the file is not empty.
// Postcondition:
// The next student record in the input file is read and stored
// in this object. The rank is save as a value of the enumeration
// type "letGrade" according to the read-in numeric rank number.
void Average();
// Precondition:
// The 3 grades (grade1, grade2, and grade3) are assigned.
// Postcondition:
// Find the average of the 3 grades.
void LetterGrade();
// Precondition:
// The average is assigned.
// Postcondition:
// Determine the letter grade according to the average.
void Print() const;
// Precondition:
// name, ssn, rank, and grade are assigned.
// Postcondition:
// Print out the student record.
StuRecord();
// Default constructor.

private:
string name;
string ssn;
Rank rank;
letGrade grade;
int grade1, grade2, grade3, average;
};

And a source file...which i am not sure what to do from this point forward =(

#include "project 1.h"
#include <iostream>
#include <fstream>

using namespace std;




enum Rank {Freshment, Sofomore, Junior, Senior};
enum letGrade {A, B, C, D, F};
struct StuRecord
{
string name;
string ssn;
Rank rank;
letGrade grade;
int grade1, grade2, grade3, average;
};

Jul 08, 2010 | Compilers & Programming Tools

1 Answer

Java code for adding octal, hexadecimal subtracting binary,


Hello desireejane,


One method is to do the following

  1. Convert the octal, hexadecimal or binary to decimal.
  2. Add or Subtract the decimal normally
  3. Convert the result back to octal, hexadecimal or binary.

  • Convert the octal to decimal:

public static long octalToDecimal(String octal) throws NumberFormatException {
// Initialize result to 0
long res = 0;

// Do not continue on an empty string
if (octal.isEmpty()) {
throw new NumberFormatException("Empty string is not an octal number");
}

// Consider each digit in the string
for (int i = 0; i < octal.length(); i++) {
// Get the nth char from the right (first = 0)
char n = octal.charAt(octal.length() - (i+1));

int f = (int) n - 48;
// Check if it's a valid bit
if (f < 0 || f > 7) {
// And if not, die horribly
throw new NumberFormatException("Not an octal number");
} else {
// Only add the value if it's a 1
res
+= f*Math.round(Math.pow(2.0, (3*i)));
}
}

return res;
}



Mar 24, 2009 | Sun Java Programming Language (cdj-275)

2 Answers

Source code for word count


Haha, i wrote one of thee a while ago for a competition. You need to us e the char at function mate :D
Inside a for loop
Ill havea look for you though :D

Sep 09, 2008 | ArcMedia JavaScript Source Code 3000 Pro...

2 Answers

Armstrong problem


could you give me more info plz

Jun 21, 2008 | Compilers & Programming Tools

2 Answers

Visual basic 6.0


Use a compare (instr) command to search the sentence for punctution and spaces. Increment a variable for each word found, resetting the search string and retaining the start position of each find.

Feb 27, 2008 | Compilers & Programming Tools

Not finding what you are looking for?
Compilers & Programming Tools Logo

Related Topics:

169 people viewed this question

Ask a Question

Usually answered in minutes!

Top Compilers & Programming Tools Experts

Robin Hill
Robin Hill

Level 3 Expert

1251 Answers

Fred Block
Fred Block

Level 2 Expert

289 Answers

Les Dickinson
Les Dickinson

Level 3 Expert

18299 Answers

Are you a Compiler and Programming Tool Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...