C++ :: Simulated Radio Station Holding A Contest - Guess Number / Sequential Search
Dec 14, 2014
I have an assignment to write the code for a simulated radio station holding a contest. The contest is for a "caller" (user input obviously) to guess a number from 1 to 500. The "randomly generated" numbers are already chosen and are being stored in a .txt file. The code is to search for number guessed by the caller and if they are wrong, next caller until a caller is correct. The end result is to display the winning number, the indexed location the number was found, and how many callers guessed. This is what I have...
Code:
#include<iostream>
#include<fstream>
using namespace std;
int sequenSrch(const int prizeArray[], int arrayLength, int searchedItem);
int guess();
[Code] ....
I'm not sure if I am even on the right track... when I pass something into the sequenSrh(); the code compiles, asks for the number to be guessed and ends.
View 2 Replies
ADVERTISEMENT
Jan 22, 2013
work for a radio station as their webmaster, and we have been looking into online streaming options for the last few months for our website. Pretty much everyone charges a monthly fee for this type of service and I feel like it is something I am capable of doing myself.
At the station we have a computer dedicated to operating the music/talk. On this computer there is a program that ques all the music, ads, ect.. This would be my audio source: Either the program playing all the music, or the computer itself.
The problem I have been pondering all night is how would I access this input source? The only audio input I am familiar with accessing is .mp3 or .wav files. How can I code my program to access this audio the program is producing and stream it to people on the web?
View 1 Replies
View Related
Jul 28, 2013
My assignment is to write a system for managing a radio station. The code is composed of four classes:
Song: each song has a name, a composer and a singer, and has a few segments: INTRO,VERSE,CHORUS,TRANSITION, while each represents a different length string of chars.
Playlist: a multiset of songs, and a pointer to a RadioStatistics instance (see below).
RadioStation: a set of Songs (will represent the station database), and a list of Playlists, each playlist holds a few songs from the database.
RadioStatistics: can only be instantiate once, this object gather statistics; it has two maps: one that counts how many times a song was played, and second that counts how many times each singer was played. (the key is the song/singer name, and the value is the counter).
The RadioStation has a constant that defines a limit to how many times a song is allowed to be played. whenever a song reaches this limit (meaning, it was played too much), the program needs to skip to the next song in the database.
so, I run this test from main, and the program crashes (or more accuratly get stuck, since the console stays open and the program keeps working until I stop it).
I made a few changes and run the debugger a few times, and was able to focus on the problem.
Song.h:
Code:
#ifndef SONG_H_
#define SONG_H_
#include<iostream>
#include<string>
[Code] ....
I ran a step by step debugger, and found out the problem lays with line 90 in RadioManager.cpp, when the while loop runs its fourth iteration. It crashes when it tries to dereference the iterator, while it points to the fourth playlist in the list.
And here's some more weird stuff: when I comment out line 73 in main.cpp - it works perfectly fine! (line 73 in particular! commenting out any other line in main.cpp didn't worked around the bug!)
View 13 Replies
View Related
Sep 16, 2013
Write a program to find the number of comparisons using the binary search and sequential search algorithms
//main.cpp
#include <cstdlib>
#include <iostream>
#include "orderedArrayListType.h"
using namespace std;
int main() {
cout << "." << endl;
[code]....
View 4 Replies
View Related
Jan 1, 2015
i developed the code below to improve the solutions of a vehicle routing problem with a variable negborhood search. in this case one element is exchanged, i case no better solution is found two elements are exchanged and in case no better solution is found tree elements are exchanged with the funktions one exchange two exchange and tree exchange. as acceptance criteria the new solution is accepted if new solution <oldsolution or the criteria e^(newsolution-oldsolution)<u where u is a random number between 0 and 1. the code below is running but the solutions do not change at all from the solution bevore the change algorithnmus. to be more clear i have to say that first a starting solution is constructed and the solution after the exchange algorithm shouls be better thahn the start solution but although all loops are executed the solution stays the same.
how to imporve the exchange functions one exchange two exchange tree exchange so that a better solution in found.in the attachment you find a txt file from which the data is read in.
// library includes
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <map>
[code]....
View 13 Replies
View Related
Aug 9, 2013
I have an error on my Guess the random number game.When you got the right answer it shows the "You got the right answer" and shows the "What is the number?" Here is the code.
Code:
#include<stdio.h>
main()
{
srand(time(0));
int x=rand() % 101,guess=0,tries=3;
printf("The computer will generate a random number, try and guess the random number.
}
[code]....
View 3 Replies
View Related
Jun 11, 2013
Write a program that plays the game of guess the number.the program chooses the number to be guessed by choosing an integer at random in the range 1-1000. The program then types 'i have a number between 1 and 1000,can you guess number? Then the player then types the first guess, the program responds.
View 1 Replies
View Related
Feb 11, 2013
I'm currently creating a guessing game program where the user will be asked to guess the computer generated number. Once the program is finished, at the end the user will be asked if they want to play again. If the user types "Y or Y" the program will loop and when the user types "n or N" it will not loop. Check out my code below.
#include<iostream.h>
#include<stdio.h>
#include<dos.h>
#include<stdlib.h>
#include<conio.h>
#define g gotoxy
void main(){
int a,l,b,guess,row,col,answer,num,clue=5;
[Code] ....
I can't loop this program.
View 3 Replies
View Related
Nov 28, 2013
I have a character with x and y coordinates. When I set the coordinates in DungeonLevel, the values are gone by the time I try to get them in the main function.
Here is my main function:
#include <iostream>
#include <random>
#include <ctime>
[Code]....
View 2 Replies
View Related
Feb 6, 2014
In this program what i'm doing is to search for a number when the vector is in order, and count how many times that number appears, the problem is that count how many times the number does not appear, but when its appear the program stays in an "standby mode" and the cursor does not move.
int buscarNumOrdenado (int x [MAX]) //MAX is the define {
int num,d, LimiteInferior, LimiteSuperior,mitad;
d=0;
LimiteInferior = 0;
LimiteSuperior = MAX-1;
[Code] ....
View 2 Replies
View Related
Jun 30, 2014
I need a variable that will just hold a function that I can change in the middle of the application, even to different function type with different amount of parameters ... is this even possible? At the moment I have this
struct REPLY {
string *sReply;
function<int()> special = [](){return 0;};
REPLY()
[Code] .....
And then change it back to blank function returning 0 after calling it
(reply.special)();
reply.special = [](){return 0;};
This works fine (there is no reason why it should not, right? Now, if I want to have another function, let's say
void test2(string str) {
MessageBox(NULL, str.c_str(), NULL, NULL);
}
How do I point this one to the variable special, when I want to call it like that (or something similar)
(reply.special)("test string");
is this even possible? if so, how? i tried to create function pointer (didnt compile at all) or use template (neither did this) and how to do this as I discovered functional lib just a while ago.
View 12 Replies
View Related
Mar 10, 2014
I'm still a beginner at C++ programming, I have tried to implement some optimization algorithms (related to database) in C++, I cannot say it is going as far as I thought it will be, some errors does not even make sense, I will cut to the chase, I need to implement SA (Simulated Annealing) in C++, SA, which is an example of the Randomized Algorithms, functions on the concept of randomness and probability. In addition, I searched the internet with no (let say "accurate") code that might give me insight on how to begin, I only found one code for SA that I could understand, and edited it (which will be shown below), still looking to enhance and correct it more.
The code for SA is as follows:
Code:
#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <cmath>
[Code] .....
If the concept of Simulated Annealing is not clear, you may refer to the following papers which can be found in a simple Google search: Simulated Annealing Algorithms: an overview.An Introduction to Interacting Simulated Annealing. Query Optimization (there is a sub-section for Simulated Annealing in this paper that explains SA briefly) ....
View 6 Replies
View Related
Nov 26, 2014
I'm trying to simulate a ctrl+ keypress into a running application.
Code:
#include <stdio.h>
int main (void) {
system("/usr/local/bin/rundb");
}
My problem is that the rundb program needs the user to type ctrl-b then s to actually start executing. What is the best way to handle this automatically? Some sort of fork/pipe?
View 3 Replies
View Related
Mar 14, 2015
We are working on building a cluster and needed to create or find a program writen in C that we can run. I was thinking a program that finds prime numbers and insert them into a MySQL database. I have never worked with C so I don't know where to start or anything. I have a week to prove our project is worth keeping and our cluster is almost completely installed we just need to create a program.
View 4 Replies
View Related
Jun 30, 2014
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
int turn = 1;
int counter = 0;
int t, n;
[Code] ....
I found this program in a forum and it creates 1 to t threads with each thread pointing to the next and the last thread pointing to the first thread and it allows each thread to sequentially take a turn until all threads have taken n turns. That is when the program ends.
My doubt is if we see in void *tFunc(void *arg) function, first thread locks the mutex and then wait there forever till it's turn comes.Lets say if I spwan 1000 threads and they have take 10 turns each sequentially and what if a 550th thread locks the mutex as soon as the program starts and waiting for its turn which will never happen because still (turn=1) which means it's first thread's turn and first 549 threads have to complete their 1st turn before this 550 threda's turn comes.Doesnt this result in deadlock?
View 2 Replies
View Related
Nov 3, 2013
How do i go about updating a specific record in sequential File using a primary key in c++. I used Inventory number as my primary key..
Code: int locate[2];
string fname, lname, add, name, address;
int num, foundit;
Customer customer;
[Code].....
View 6 Replies
View Related
Feb 2, 2015
[size="5"][size="4"]
I am programming in C and am having some trouble finding the .txt file I saved after having run my program. It is likely a stupid error on my behalf. However, it is causing me quite a bit of grief at the moment. I attached my source code below
abgcchp27ex1.txt (2.01K)
I coded my structure within my header file(bookInfo.h) correct along with everything else. My dilemma is a matter of my file location and whether it actually saved.
/* This program takes the book info program from chapter 27 and writes the info to a file named bookinfo.txt. */
// First include the file with the structure definition
#include "bookInfo.h"
#include
#include
FILE * fptr;
[Code]....
View 3 Replies
View Related
Sep 3, 2013
Basically i need to make a number guessing game where user thinks of a numbver from 1 - 100 and the machine will try to guess it in the least number of times. Once it guesses the number it will also say how many tries it took to guess.
My code so far is
#include<iostream>
using namespace std;
const int MAX = 100;
int main() {
char ch;
cout << "Think of an integer number between 0 and " << MAX<<endl;
cout << "Write it down on a piece of paper then hit a key to continue"<<endl<<endl;
cin.get(ch);
[Code] ....
View 2 Replies
View Related
Apr 23, 2015
My assignment is "Search Benchmarks: Write a program that has a sorted array of at least 20 integers. It should call a function that uses the linear search algorithm to locate one of the values. The function should keep a count of the number of comparisons it makes until it finds the value. The program then should call a function that uses the binary search algorithm to locate the same value. It should also keep count of the number of comparisons it makes. Display these values on the screen."
I'm unsure how to make it show the number of comparisons it takes to find the value for the binarySearch function. Also, where to put the selectionSort function the teacher said we need. This is what I have...
#include <iostream>
using namespace std;
int linearSearch(const int a[], int num);
int binarySearch(const int a[], int num);
void selectionSort(int a[]);
[Code] .....
View 1 Replies
View Related
Mar 23, 2014
i'm trying to use binary search to find a number in the array but i dont know whats wrong with my code. When l enter a number which DOES exist in the array, everything is ok... but when i enter a number which does NOT exist in the array, i have problem...i cant exit the program, it just continues to run.Here is my code
int main()
{
int FirstPosition;
[Code]....
View 2 Replies
View Related
Feb 20, 2013
Write a C++ program that uses a while loop to guess a persons age, ask the user if the want to try again if no end the loop. Of course if they guess it the loop also ends
View 3 Replies
View Related
Aug 14, 2014
I have a file that I need to read in blocks. I need to read in n lines at a time, do some processing, and then read in the next block of n lines until the file is done. I know the size of the block, but not the number of lines in the file unless I check that first. Normally I would read in like,
Code:
// declarations
string new_input_line, input_file;
// create an input stream and open the input_file
ifstream input_file_istream;
input_file_istream.open( input_file.c_str() );
[Code] .....
// process through data_block
With this approach, I'm not sure how I would keep looping to read the next block until I hit the end of the file without knowing how many lines are in the input file. I could process the file to find that out, or get that number from bash and pass it it as an argument, but it seems like that shouldn't be necessary.
I could also read in and store the entire file as a vector of string and then process through it afterwords, but that would not be a very efficient use of memory.
View 1 Replies
View Related
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
Nov 23, 2014
So I have an issue with a homework assignment that I am coding. I am attempting to get a function to iterate through an array and search for a number that was stored in an array by the user. So far I can take the number, get the numbers displayed but in my menuChoice2 function, for some reason the program is not confirming whether or not the number is entered, and is only telling me that the number has not been found, instead of confirming that the number is in the array.
Here is my code thusfar:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
// Variables that are Globally declared
int menuChoice = 0;
int usernum[1000] = { ' ' };
[Code] .....
To be clear I am not getting any errors but something is telling me that the error is in the formatting of menuChoice2.
View 14 Replies
View Related
Oct 28, 2014
I am working on a website so you can order online for a restaurant. I currently figured out how to get values of all checkboxes and dropdownlists but i still cannot seem to figure out radio buttons.
Right now i am just making a super string with all of the selected values but eventually i am going to want to make a receipt with a checkout page.
//this seems to work alright
XPathNodeIterator toppingIterator = myNavigator.Select("//my:ToppersGroup", NamespaceManager);
s +=+ "";
while (toppingIterator.MoveNext()) {
XPathNavigator node = toppingIterator.Current;
XPathNodeIterator children = node.SelectChildren(XPathNodeType.All);
while (children.MoveNext())
[Code] .....
View 5 Replies
View Related
Apr 30, 2014
I wrote program for Sequential matrix multiplication .But after execution for any input value( ex. 100,150,400) it shows the execution time is 0.000 msec.
#include <stdio.h>
#include <math.h>
#include <sys/time.h>
void print_results(char *prompt, int N, float *a);
int main(int argc, char *argv[])
[Code] ......
View 2 Replies
View Related