Question

Hi there! I need to fix the errors that this code is giving me and also...

Hi there!
I need to fix the errors that this code is giving me and also I neet to make it look better.
thank you!



#include <iostream>

#include <windows.h>

#include <ctime>

#include <cstdio>

#include <fstream> // file stream

#include <string>

#include <cstring>

using namespace std;
const int N=10000;
int *freq =new int [N];
int *duration=new int [N];
char const*filename="filename.txt";
int songLength(140);

char MENU(); // SHOWS USER CHOICE

void execute(const char command);



void About();

void Save( int freq[],int duration[],int songLength);

void Load(char const*filename,int freq[],int duration[],int N);

void Play( int freq[],int duration[],int songLength);

void Delay(int duration[],int songLength);

void Speed(int duration[],int songLength);







//MENU CHOICES//

const char ABOUT = '0';

const char SAVE = '1';

const char LOAD = '2';

const char PLAY = '3';

const char DELAY = '4';

const char SPEED = '5';

const char QUIT = 'Q';





int main()

{

char command;



do

{

command = MENU();//ASSIGN THE MENU IN FUNCTION

execute(command);//EXECUTE THE MENU

system("PAUSE");//PAUSE THE SYSTEM



} while (toupper(command) != 'Q');



return 0;



}



char MENU()

{

char c;

do {

system("cls");

cout << "MENU\n";

cout << "0.....About\n";

cout << "1.....SAVE Data\n";

cout << "2.....LOAD Data\n";

cout << "3.....PLAY\n";

cout << "4.....DELAY\n";

cout << "5.....SPEED\n";

cout << "Q.....Quit\n";

cout << "choice: ";



cin >> c;

} while (!('0' <= c && c <= '5') && ((c!='q') && (c != 'Q')));



return c;

}



void execute(const char command) {

switch(toupper(command))

{

case ABOUT: About();

break;

case SAVE: Save(freq,duration,songLength);

break;

case LOAD: Load(filename,freq,duration,N);

break;

case PLAY: {
Play(freq,duration,songLength);


break;
}
case DELAY: Delay(duration,songLength);

break;

case SPEED: Speed(duration,songLength);

break;



}

}



void About() { cout << "write about your group member names and credits." << endl; }

void Save(int freq[],int duration[],int songLength)
{
ofstream fout;
fout.open("filename2.txt");
cout<<"saving.."<<endl;
int i=0;
fout<<freq[i]<<duration[i];
while (!fout.eof()&&i<N){
songLength++;
i++;
fout<<freq[i]<<duration[i];
}
fout.close();
cout<<"complete"<<endl;
}

void Load(char const *filename,int freq[],int duration[],int N)
{
cout << "Loading...\n" ;
ifstream infile;
infile.open(filename,ios_base::in);
if(!infile.is_open()){
cout<<filename<<"could not be opened\n";
return;
}
cout<<"loading song..."<<endl;
int i=0;
infile>>freq[i]>>duration[i];
int songLength(0);
while (!infile.eof()&&i<N){
songLength++;
i++;
infile>>freq[i]>>duration[i];

}
infile.close();
cout<<"complete"<<endl;
}

void Play(int freq[],int duration[],int songLength) {
for (int i=0;i<songLength;i++)
{
Beep(freq[i],duration[i]);
}
}

void Speed(int duration[],int songLength) {
for (int i=0;i<songLength;i++){
duration [i]-100;
}
}
void Delay(int duration[];int songLength){

for(int i=0;i,songLength;i++){
duration[i]+200;

}


0 0
Add a comment Improve this question Transcribed image text
Answer #1

Just make the delay function as given in the screenshot below :-

Joid Delay (int duration[], int songLength) { for(int i=0;i, songLength; i++){ duration[i]+200;

Add a comment
Know the answer?
Add Answer to:
Hi there! I need to fix the errors that this code is giving me and also...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string>...

    Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; //function void displaymenu1(); int main ( int argc, char** argv ) { string filename; string character; string enter; int menu1=4; char repeat; // = 'Y' / 'N'; string fname; string fName; string lname; string Lname; string number; string Number; string ch; string Displayall; string line; string search; string found;    string document[1000][6];    ifstream infile; char s[1000];...

  • Code in C++: Please help me fix the error in function: void write_account(); //function to write...

    Code in C++: Please help me fix the error in function: void write_account(); //function to write record in binary file (NOTE: I able to store data to a txt file but however the data get error when I try to add on data the second time) void display_all(); //function to display all account details (NOTE: This function is to display all the info that save account.txt which is ID, Name, and Type) void modify_account(int); //function to modify record of file...

  • Today assignment , find the errors in this code and fixed them. Please I need help...

    Today assignment , find the errors in this code and fixed them. Please I need help with find the errors and how ro fixed them. #include <iostream> #include <cstring> #include <iomanip> using namespace std; const int MAX_CHAR = 100; const int MIN_A = 90; const int MIN_B = 80; const int MIN_C = 70; double getAvg(); char determineGrade(double); void printMsg(char grade); int main() { double score; char grade; char msg[MAX_CHAR]; strcpy(msg, "Excellent!"); strcpy(msg, "Good job!"); strcpy(msg, "You've passed!"); strcpy(msg, "Need...

  • I have 2 issues with the C++ code below. The biggest concern is that the wrong...

    I have 2 issues with the C++ code below. The biggest concern is that the wrong file name input does not give out the "file cannot be opened!!" message that it is coded to do. What am I missing for this to happen correctly? The second is that the range outputs are right except the last one is bigger than the rest so it will not output 175-200, it outputs 175-199. What can be done about it? #include <iostream> #include...

  • Please help fix my code C++, I get 2 errors when running. The code should be...

    Please help fix my code C++, I get 2 errors when running. The code should be able to open this file: labdata.txt Pallet PAG PAG45982IB 737 4978 OAK Container AYF AYF23409AA 737 2209 LAS Container AAA AAA89023DL 737 5932 DFW Here is my code: #include <iostream> #include <string> #include <fstream> #include <vector> #include <cstdlib> #include <iomanip> using namespace std; const int MAXLOAD737 = 46000; const int MAXLOAD767 = 116000; class Cargo { protected: string uldtype; string abbreviation; string uldid; int...

  • In C++: Please help me correct this code .... All parts with (FIX ME) #include <algorithm> #include <climits&gt...

    In C++: Please help me correct this code .... All parts with (FIX ME) #include <algorithm> #include <climits> #include <iostream> #include <string> // atoi #include <time.h> #include "CSVparser.hpp" using namespace std; //============================================================================ // Global definitions visible to all methods and classes //============================================================================ const unsigned int DEFAULT_SIZE = 179; // forward declarations double strToDouble(string str, char ch); // define a structure to hold bid information struct Bid { string bidId; // unique identifier string title; string fund; double amount; Bid() {...

  • I need to update this C++ code according to these instructions. The team name should be...

    I need to update this C++ code according to these instructions. The team name should be "Scooterbacks". I appreciate any help! Here is my code: #include <iostream> #include <string> #include <fstream> using namespace std; void menu(); int loadFile(string file,string names[],int jNo[],string pos[],int scores[]); string lowestScorer(string names[],int scores[],int size); string highestScorer(string names[],int scores[],int size); void searchByName(string names[],int jNo[],string pos[],int scores[],int size); int totalPoints(int scores[],int size); void sortByName(string names[],int jNo[],string pos[],int scores[],int size); void displayToScreen(string names[],int jNo[],string pos[],int scores[],int size); void writeToFile(string...

  • Hello, I have some errors in my C++ code when I try to debug it. I...

    Hello, I have some errors in my C++ code when I try to debug it. I tried to follow the requirements stated below: Code: // Linked.h #ifndef INTLINKEDQUEUE #define INTLINKEDQUEUE #include <iostream> usingnamespace std; class IntLinkedQueue { private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position Node *pp ; // previous position int size; // number of elements in the queue public: IntLinkedQueue();...

  • c++, I am having trouble getting my program to compile, any help would be appreciated. #include...

    c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...

  • C++ how can I fix these errors this is my code main.cpp #include "SpecialArray.h" #include <...

    C++ how can I fix these errors this is my code main.cpp #include "SpecialArray.h" #include <iostream> #include <fstream> #include <string> using namespace std; int measureElementsPerLine(ifstream& inFile) {    // Add your code here.    string line;    getline(inFile, line);    int sp = 0;    for (int i = 0; i < line.size(); i++)    {        if (line[i] == ' ')            sp++;    }    sp++;    return sp; } int measureLines(ifstream& inFile) {    // Add your code here.    string line;    int n = 0;    while (!inFile.eof())    {        getline(inFile,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT