C++ :: Convert Pseudo Code Into Program For Searching Value Of Array
Jun 29, 2014
What is the program of this pseudo code?
Set found to false.
Set position to -1.
Set index to 0.
While found is false and index < number of elements
If list[index] is equal to search value
found = true.
position = index.
End If
Add 1 to index.
End While.
Return position
View 5 Replies
ADVERTISEMENT
Apr 15, 2013
I have assignment which requires me to print out and array code and a pseudo code. I dont no what a pseudo code is,.
View 2 Replies
View Related
Feb 20, 2014
I have made a program that converts or reverses an input string. Here is my code working fine
static void Main(string[] args){
string input = Console.ReadLine();
string[] words = input.Split(' ')
for (int i = words.Length; i > 0; i--)
Console.Write(words[i - 1] + " ");
Console.WriteLine();
Console.ReadLine();
}
How can I write this program in pseudo code?
View 2 Replies
View Related
Sep 12, 2014
I'm doing a practice problem where I need to read pseudo code and understand what it does.
For this code, I believe it will move the robot forward while i<650, so it moves it forward for 650 steps in total. Then it sets the motors to 0 when it's finished.
Code:
while(i<650)
{ rotateCW(2);
rotateCCW(1);
Delay1KTCYx(50);
i++;
LATD=0x00; //Set all Port D to 0
}
This code I'm having the most trouble with. So while(1) the pot(potentiometer) read's the ADC. Then it scales the adc, not 100% sure what the +20 and *.22 mean, I think it has to do with binary conversions?
Now it sets pin 1 of port 1 to 0, delays based on pot above, and sets it back to 1, and delays again. I assume something to do with controlling motor speed based on the potentiometer.
Code:
void main(void){TRISD = 0x00; // Setting port D to outputs
LATDbits.LATD0 = 1; // Setting bit 0 of port D to 1
while(1) {
pot = readADC();
pot = pot * 0.2297 + 20;
[Code] ......
My best guess is: The car moves forward 400 steps, stop, turn right for 230 steps, stop. At this point it would begin moving straight, and it would turn left/right as needed to keep the robot in the center of the track.
Code:
void main(void) {
for(i=0;i<400;i++) {
rotateCW(2,motor); //Rotate motor two (one step)
rotateCCW(1,motor); //Rotate motor one (one step)
Delay1KTCYx(50);
[Code].....
View 5 Replies
View Related
Apr 27, 2014
Write a program to implement the following Pseudo Code using three semaphores.
Here is the pseudo code:
int sizeofbuffer = 10
semaphore Access = 1, Item = 0, EmptySpace = sizeofbuffer;
int nNumberOfItem = 0;
void Farmer() {
while ( true ){
semWait( EmptySpace );
[Code] .....
View 3 Replies
View Related
Jan 3, 2015
I want to create a top trumps game using pseudo code with variables, loops, If statements and inputs, how would I write it?
View 3 Replies
View Related
Apr 15, 2013
I have finished writing the code for the following program. I have concerns with the pseudo-code that I have written and the flow chart seems really complicated. I dont know how to build it. Here is the question:
An Internet service provider has three different subscription packages for its customers:
Package A: For $9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour.
Package B: For $14.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour.
Package C: For $19.95 per month unlimited access is provided.
Write a program that calculates a customer s monthly bill. It should ask which package the customer has purchased and how many hours were used. It should then display the total amount due.
Input Validation: Be sure the user only selects package A, B, or C. Also, the number of hours used in a month cannot exceed 744
Here is my program:
#include <iostream>
using namespace std;
int main() {
char package;
int hours;
[code]....
What should be my pseudocode and flowchart ? Can i copy and paste my pseudocode here ?
View 2 Replies
View Related
Oct 26, 2014
Design an algorithm using flowchart or pseudo-code to prompt the user for a series of positive integer values. Calculate the average of these values and display the average at the end of the program. Assume that the user types the sentinel value -1 to indicate end of data entry.
Sample input-output:
Enter a positive integer (-1 to end) : 5
Enter a positive integer (-1 to end) : 7
Enter a positive integer (-1 to end) : 6
Enter a positive integer (-1 to end) : -1
The average value is: 6
I searched online and found out this solution however it is only for three numbers.Is there any way of modifying this to include the sum of x numbers / number of x(integers) to find the average?
View 5 Replies
View Related
Dec 17, 2014
i use cygwin and i have a program that was returning an error saying "undefined reference" and i figured out that i misspelled a word. how can i search for the misspelling in the input mode, if ive just completed a very large program and dont want to scroll through possibly 300+ lines of input? im not totally out the loop, but i know i can "vim program.cpp" to open the program, but before clicking "i" to actually edit, there must be a way to search a word
View 9 Replies
View Related
Apr 17, 2014
I'm writting program and need to convert int ot char array without simbol. I have tryed snprintf , but his returns array full of simbols if it is initilized elsware return full of garbidge. Is there any elegent way to aceave this? What I'm trying to aceave is liek this:
char buffer[10];
int temp = 1231423;
// Do conversation...
// After conversation char array should look like this
// 1 2 3 1 4 2 3 _ _ _
// without simbol
View 2 Replies
View Related
Oct 12, 2013
Basically I initialize an int array of size 10 with zeros. Then element 7 is changed to 1. Via cin I collect a user input (integer) which is the number to be searched.
Now the problem is that the search function from the book is somehow not working. I added a function to see how the array looks like and there is definitely one element with value 1 that should be found, but it simply isn't. The function always returns -1 (element not found).
The program compiles, but doesn't work as it is supposed to.
//********************************************************
// search algorithm for arrays
//********************************************************
#include <iostream>
using namespace std;
[Code].....
View 5 Replies
View Related
Feb 28, 2013
I have to search an array of struct students on the basis of their first names, last names and roll numbers .. so far i am done with the input of the student first , last names and roll numbers . I have problem in searching the array ..
Code:
#include <iostream> Code: #include <string>
using namespace std;
struct Student {
string FirstName ;
string LastName ;
[Code] ....
View 5 Replies
View Related
Jan 22, 2013
I have a linear search algorithm set up to search through an array of class objects it works but the output does not match, when i search for a particluar name in the array the 1st and third values int the array are found but the second value is not found..
below is my code:
int linsearch(string val) {
for (int j=0; j <= 3; j++) {
if (player[j].getLastName()==val)
return j ;
[Code] .....
View 2 Replies
View Related
Nov 23, 2014
I'm trying to open a text file from my computer and randomly output a random line of text (string) onto the console. How do I go about doing this?
So for example, if my text file, "StringTextFile.txt" had 50 rows of strings datas (not integers or chars), how would I randomly generate a line of word from the 50 rows of words in the StringTextFile.txt and output it onto the console?
This is how far I've gotten, which isn't much, but somewhere. I don't even know if my code even makes sense, at this point I'm just randomly shoving code together.
#include <fstream>
#include <iostream>
#include <string>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <ctime>
[code]......
View 1 Replies
View Related
Sep 22, 2013
I am getting an error...
Error1error C2109: subscript requires array or pointer type451
PHP Code:
#include "stdafx.h"
#include <conio.h>
#include <iostream>
using namespace std;
//Function prototype
int searchList (const int [ ], int);
[code].....
View 3 Replies
View Related
Jan 31, 2013
My program generates an array of random numbers. I want to then search a specific number within the array. If the number is in the array then a message apopears on the console saying that its there. I'm using the binary search algorithm to do this.
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <cstring>
using namespace std;
int size;
int getSize() { return size; }
[Code] ......
View 2 Replies
View Related
Aug 26, 2013
I am having a problem printing out the results for my code, It is supposed to print out the largest and smallest value in the array, but keeps giving me a value not entered and I don't know why.
//This program lets the user enter 10 numbers and then display the highest and lowest number.
#include <iostream>
#include<stdio.h>
using namespace std;
int main() {
const int NUM_ENTERED = 9;
int number[NUM_ENTERED], highestValue = number[0], lowestValue = number[0], count=0;
[Code] .....
View 2 Replies
View Related
Feb 6, 2013
How can I generate a pseudo-random real number from interval [0,1] ?
Can it be generalized to any interval? Like [0,a], where 'a' is a parameter?
I tried searching for it, I only found rand(), srand(), random(1), and randomize. None of it actually seems to work for me..
Later I actually succeeded with something like
srand( (unsigned)time( NULL ) );
printf( " %6d
", rand() );
but it only produces up to five digits integers and I cannot divide by 99999 to get it into [0,1].
View 11 Replies
View Related
May 8, 2014
I'm having trouble converting this binary search with an int array to use a string array..
Code:
#include <iostream>
#include <string>
using namespace std;
// Function prototype
int binarySearch(string [], int);
[Code] .....
View 3 Replies
View Related
Mar 2, 2012
I have the following code which attempts to assign a u_int8 array of 256 to an unsigned char[256]:
Code:
unsigned char testData[256]=pSample->data;
I get the compilation error:
error C2440: 'initializing' : cannot convert from 'const uint8_t [256]' to 'unsigned char [256]'
What is the safe way to cast or convert here?
View 3 Replies
View Related
Sep 7, 2013
I've been wondering how some program using codes is animated?
View 3 Replies
View Related
Aug 24, 2013
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <SDL/SDL.h>
[Code]....
I don't know why since I've assigned a value like that to a variable of that same type before. Unless I had garbage data somewhere and didn't realize it.
View 9 Replies
View Related
Apr 24, 2013
//code
ofstream outFile;
outFile.open("p4a.dat");
outFile << setw(8) << "90.0";
outFile << setw(8) << "75.0";
outFile << setw(8) << "36" << endl;
[Code] .....
View 1 Replies
View Related
Apr 23, 2013
who can provide a souce code for autopilot helicopter. because i'm doing a project.
View 4 Replies
View Related
Apr 28, 2015
IM trying to make a simple program that will display morse code. Ex if you type 0 print should be (-----) and all the way up to 5. The problem is though that all printf displays all the numbers and not executing only the assigned variable.
#include<stdio.h>
int main(void) {
int a , b , c , d , e, f, x;
a = 0;
b = 1;
c = 2;
d = 3;
e = 4;
f = 5;
x = 6;
[Code] ....
View 4 Replies
View Related
May 13, 2013
I made this program to convert bits to bytes, because I'm so sick of seeing ISP's advertise speeds in megabits, which I consider an intentional attempt to decieve :P And I think I've finally understood how the return value of scanf works since the last time I posted here, so my program can check to see if an integer was entered before processing the input, but I'm stuck on how to make the whole program start over if an integer is not entered. I have a hunch it would involve a loop, but I can't figure out how to make the program start over at "How many mb do you need converted?" if an integer is not entered into scanf..Here is the code I have so far:
Code:
#include <stdio.h>
int main () {
int b, mb, kb, Byte, kB, mB, gB;
char term;
}
[code]....
and my program makes the assumption for now at least, that mb will be inputted because that's the unit of measurement that i usually see advertised, and i didn't bother making an if statement to print a conversion in terms of gigabytes because i've never heard of a connection that fast :P
View 5 Replies
View Related