Question

In: Computer Science

Find and fix the compile time bugs in the code at the end of this section....

Find and fix the compile time bugs in the code at the end of this section. Compile time bugs show as errors when you compile, but the Visual Studio IDE also gives you visual clues in the form of red squiggly underlines, as shown here. This assignment is meant to test your attention to detail and strengthen your debugging skills.

Here is the code.

// Week 4 Assignment-1

// Description: Compile time errors

//----------------------------------

//**begin #include files************

#include <iostream> // provides access to cin and cout

#include <fstream> // provides access to file commands

#include <string> // provides access to string commands

#include <vectors> // provides access to std::vector

//--end of #include files-----------

//----------------------------------

using namespace std;

//----------------------------------

//**begin global constants**********

//--end of global constants---------

//----------------------------------

//**begin main program**************

int main()

{

       // create and initialize variables

       string myTextString;

       string myFilename;

       vector <string> myStrVector;

       ifstream inFile;

       ofstream outFile;

       cout << "enter a file name (without an extension): " << endl;

       getline(cin, myFilename);

       myFilename += ".txt";

       // open an output file

       outfile.open(myFilename);

       // write to a file

       for(int i = 0; i < 3;i++)

       {

              cout >> "enter a line of text: ";

              getline(cin, myTextString);

              outFile << myTextString << endl;

       }

       // close the file

       outFile.close();

       // open an input file

       inFile.open(myFilename);

       // read from the file

       while (getline(inFile,myTextString))

       {

              myStrVector.push_back(myTextString);

       }

       inFile.close();

       // use a range-based for loop with a switch statement

       for(auto s: myStrVector)

       {

              cout << s << endl;

              char switchFlag = s[0];

              switch (switchFlag)

              {

              case "a":

                     cout << "Hey, a vowel. The 'a' vowel actually." << endl;

                     break;

              case 'e':

                     cout << "See vowel. See vowel run. run vowel, run. The 'e' vowel." << endl;

                     break;

              case 'i':

                     cout << "I know. It's a vowel. The 'i' vowel." << endl;

                     break;

              case 'o':

                     cout << "Oh! Don't you know, it's the 'o' vowel." << endl;

                     break;

              case 'u':

                     cout << "Whew! We got a you. Actually, the 'u' vowel." << endl;

                     break;

              case 's':

                     cout << "Oh great! I love 's's. More 's's, please." << endl;

                     break;

              default

                     cout << "Nothing interesting here. I would really like to see an 's'." << endl;

                     break;

              }

       }

       // Wait for user input to close program when debugging.

       cin.get();

       return 0;

}

//--end of main program-------------

//----------------------------------

Solutions

Expert Solution

Here is compiled code:

//**begin #include files************
#include <iostream> // provides access to cin and cout
#include <fstream> // provides access to file commands
#include <string> // provides access to string commands
#include <vector> // provides access to std::vector
//--end of #include files-----------
//----------------------------------


using namespace std;
//----------------------------------

//**begin global constants**********

//--end of global constants---------
//----------------------------------

//**begin main program**************
int main()
{
// create and initialize variables
string myTextString;
string myFilename;
vector <string> myStrVector;
ifstream inFile;
ofstream outFile;
cout << "enter a file name (without an extension): " << endl;
getline(cin, myFilename);
myFilename += ".txt";
// open an output file
outFile.open(myFilename.c_str());
// write to a file
for(int i = 0; i < 3;i++)
{
cout << "enter a line of text: ";
getline(cin, myTextString);
outFile << myTextString << endl;
}
// close the file
outFile.close();
// open an input file
inFile.open(myFilename.c_str());
// read from the file
while (getline(inFile,myTextString))
{
myStrVector.push_back(myTextString);
}
inFile.close();
// use a range-based for loop with a switch statement
for(int i = 0 ; i < myStrVector.size() ; i++)
{
    string s = myStrVector.at(i);
cout << s << endl;
char switchFlag = s[0];
switch (switchFlag)
{
case 'a':
cout << "Hey, a vowel. The 'a' vowel actually." << endl;
break;
case 'e':
cout << "See vowel. See vowel run. run vowel, run. The 'e' vowel." << endl;
break;
case 'i':
cout << "I know. It's a vowel. The 'i' vowel." << endl;
break;
case 'o':
cout << "Oh! Don't you know, it's the 'o' vowel." << endl;
break;
case 'u':
cout << "Whew! We got a you. Actually, the 'u' vowel." << endl;
break;
case 's':
cout << "Oh great! I love 's's. More 's's, please." << endl;
break;
default:
cout << "Nothing interesting here. I would really like to see an 's'." << endl;
break;
}
}
// Wait for user input to close program when debugging.
cin.get();
return 0;
}

Output:


Related Solutions

Fix the bugs in this matlab program so that it solves. clear clf clc time =...
Fix the bugs in this matlab program so that it solves. clear clf clc time = linspace(0, 5, 100); m = 1; k = 100; c = 1; delta = 0.2; [period, response] = Exmp(m, k, c, delta, time); plot(time, response) grid %Exmp(m, k, c, delta, time) % %________________________________________ function [T, x] = Exmp(m, k, c, delta, t) omega = sqrt(k/m); cC = 2*m*omega; if c>= cC disp('Not an underdamped system') T = 0; x = 0; return; end %...
Use the TestCorrectness.java/TestCorrectness.cpp to compile, fix, and run your code. QueueUsingStack.java is also provided, but you...
Use the TestCorrectness.java/TestCorrectness.cpp to compile, fix, and run your code. QueueUsingStack.java is also provided, but you will need to complete some codes. public class TestCorrectness {    public static void main(String[] args) throws Exception {        int queueSize = 7;        QueueUsingStack qViaStack = new QueueUsingStack(queueSize);        Queue queue = new Queue(queueSize);        System.out.println("**** Enqueue Test ****");        System.out.println();        for (int i = 1; i <= 4; i++) {            int...
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile and Execute. The...
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile and Execute. The project is below, I have supplied the code and I'm getting an error in SavingsAccount.h file. 17   5   C:\Users\adam.brunell\Documents\Classes\C++\Week4\SavingsAccount.h   [Error] 'SavingsAccount::SavingsAccount(std::string, double, double)' is protected A.Assume i.SavingsAccount: Assume an Interest Rate of 0.03 ii.HighInterestSavings: Assume an Interest Rate of 0.05, Minimum Balance = $2500 iii.NoServiceChargeChecking: Assume an Interest Rate = 0.02, Minimum of Balance = $1000 iv.ServiceChargeChecking – Assume account service charge = $10,...
In this python script find any bugs and errors which would cause the code to crash....
In this python script find any bugs and errors which would cause the code to crash. The code must be re-written correctly. After debugging make a separate list of all the errors you found in the script. contacts_list=[] # global variable, list of contacts_list, one string per contact def pause()     """ pauses program e.g. to view data or message """     input("press enter to continue") def load():     """ populate list with data """          contacts_list.append(('Milo ', '063847489373'))...
Homework: You are to locate the file ```src/mutDetect_todo_i.py``` in which you are to fix twelve bugs...
Homework: You are to locate the file ```src/mutDetect_todo_i.py``` in which you are to fix twelve bugs to run the program. Your output should look _exactly_ like that featured in the assignment lab. Please read the assignment sheet for other details about the lab. #mutDetect_todo_i.py ############################################################################ # TODO: There are twelve EMBARRISING silly bugs to fix. Can you find them?! ############################################################################ DATE = "16 Sept 2019" VERSION = "i" AUTHOR = " myName" AUTHORMAIL = "@allegheny.edu" def help(): h_str = "...
Need to fix this code for tc -tac-toe game .. see the code below and fix...
Need to fix this code for tc -tac-toe game .. see the code below and fix it #include <iostream> using namespace std; void display_board(); void player_turn(); bool gameover (); char turn ; bool draw = false; char board [3][3] = { {'1', '2', '3'}, { '4', '5', '6'}, { '7', '8', '9'}}; int main() { cout << " Lets play Tc- Tac- toe game " <<endl ; cout << " Player 1 [X] ----- player 2 [0] " <<endl <<endl;...
Ex1) Download the code from the theory section, you will find zipped file contains the code...
Ex1) Download the code from the theory section, you will find zipped file contains the code of Singly linked list and Doubly linked list, in addition to a class Student. In Class SignlyLinkedList, 1. There is a method display, what does this method do? 2. In class Test, and in main method, create a singly linked list objet, test the methods of the list. 3. To class Singly linked list, add the following methods: a- Method get(int n), it returns...
Ex1) Download the code from the theory section, you will find zipped file contains the code...
Ex1) Download the code from the theory section, you will find zipped file contains the code of Singly linked list and Doubly linked list, in addition to a class Student. In Class SignlyLinkedList, 1. There is a method display, what does this method do? 2. In class Test, and in main method, create a singly linked list objet, test the methods of the list. 3. To class Singly linked list, add the following methods: a- Method get(int n), it returns...
Can you fix the code and comment the fix Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -39 at...
Can you fix the code and comment the fix Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -39 at CaesarCipher.encrypt(CaesarCipher.java:28) at CaesarCipher.main(CaesarCipher.java:52) public class CaesarCipher{     char[] encoder = new char[52];     char[] decoder = new char[52];      public CaesarCipher(int rotation)      {        for(int k=0 ; k < 26 ; k++)        {            encoder[k] = (char) ('A' + (k + rotation) % 26);            decoder[k] = (char) ('A' + (k - rotation + 26) % 26);        }        for(int j...
NEED IN C++ For the following programming problems, you need to time a section of code...
NEED IN C++ For the following programming problems, you need to time a section of code in C++. For example, the following statements time the execution of the function doSomething: #include clock_t start = clock(); doSomething(); clock_t finish = clock(); double overallTime = static_cast(finish - start)/ CLOCKS_PER_SEC; Consider the following two loops: //Loop A for(i = 1; i <= n; i++)    for(j = 1; j <= 10000; j++)     sum = sum + j; //Loop B for(i = 1;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT