Question

S. The following code has some errors Please point out and correct them. (There are more than five errors #ineludo <iostream>

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

#include<iostream>

using std::cout; using std::endl;

class Time
{
public:
Time(int = 0,int = 0);
void printTime() ; //Removed const
void setMinute(int m); //removed const   
private:
int hour;
int minute;
}; //used semicolor at end which was missing

Time::Time(int h,int m)
{
   hour=(h>=0 && hour<24) ? h : 0; //used : instead of , in between h & 0 (Conditional operator ? : )
setMinute(m);
}

void Time::setMinute(int mv)//used void (as per the syntax of function which is defined outside class)
{
minute=(m>=0 && m<60) ? m : 0;
}

void Time::printTime() //used void (as per the syntax of function which is defined outside the class)
{
cout<<(hour<10 ? "0": "")<<hour<<" : "<<(minute<10 ? "0" : "")<<minute<<endl;
}

int main()
{
Time noon(12,0);
Time startTime;
Time endTime(12,45);
startTime.setMinute(15);
noon.printTime();
startTime.printTime(); //used (.) dot instead of -> because noon is not a pointer object
endTime.printTime();
system("pause");
return 0;
}

CAUserslusenDesktopDebugiOutput.ese 12: 00 0015 12 45 Press any key to continue . . . Activate Windows Go to Settings to acti

Add a comment
Know the answer?
Add Answer to:
S. The following code has some errors Please point out and correct them. (There are more...
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
  • 2 The following code has some errors. Please point out and correct them (there might be...

    2 The following code has some errors. Please point out and correct them (there might be more than 1 errors). Note: the use of const data member increment and member function print. // This code has some errors. #include using namespace std; class Increment { public: Increment( int c = 0, int i = 0); void addIncrement() const { count -= increment }; void print() const; private: int count; const int increment; }; Increment::Increment(int c, int i) { cout =...

  • 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...

  • This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a fun...

    This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a function and three overloaded operators. You don't need to change anything in the Multiplex.h file or the main.cpp, though if you want to change the names of the movies or concession stands set up in main, that's fine. Project Description: A Multiplex is a complex with multiple movie theater screens and a variety of concession stands. It includes two vectors: screenings holds pointers...

  • (16 minutes) The function below has 4 errors. It has two integer parameters representing the time...

    (16 minutes) The function below has 4 errors. It has two integer parameters representing the time in hours and minutes. It should add one to the minutes, unless the minutes value is 59, in which case it should set the minutes to 0 and add one to the hours. Changes to either parameter should change the corresponding variable argument from the function call. The function should also calculate the total number of minutes (60 times the hours plus the minutes)...

  • Java Programming The program template represents a complete working Java program with one or more key...

    Java Programming The program template represents a complete working Java program with one or more key lines of code replaced with comments. Read the problem description and examine the output, then study the template code. Using the problem-solving tips as a guide, replace the /* */ comments with Java code. Compile and execute the program. Compare your output with the sample output provided. Modify class Time2 to include a tick method that increments the time stored in a Time2 object...

  • Please help with Java programming! This code is to implement a Clock class. Use my beginning...

    Please help with Java programming! This code is to implement a Clock class. Use my beginning code below to test your implementation. public class Clock { // Declare your fields here /** * The constructor builds a Clock object and sets time to 00:00 * and the alarm to 00:00, also. * */ public Clock() { setHr(0); setMin(0); setAlarmHr(0); setAlarmMin(0); } /** * setHr() will validate and set the value of the hr field * for the clock. * *...

  • answer two question,each question has 3syntax errors,find it. 1(a) The following segment of code contains at...

    answer two question,each question has 3syntax errors,find it. 1(a) The following segment of code contains at least three (3) syntax errors that will compilation to fail with errors. Identify each of these errors and specify the solution. [2 marks each, 6 marks in total] cause #include <stdio.h> void main (void) float height; float area; printf "input height of the rectangle: ") scanf( "%f", &height) printf"input length of the rectangle: scanf"", &length); height length; area printf( area of rectangle %f high...

  • What are the errors in the following code? My professor gave us this prewritten code and...

    What are the errors in the following code? My professor gave us this prewritten code and asked us to find the errors in it so that it can run properly #include <cstdlib> #include <ctime> #include <iostream> using namespace std; // input: integer // output: none // adds five to the given parameter void addFive( int x ) { x += 5; } // input: none // output: a random number int generateRandomNumber() { srand( time(0) ); return rand() % 100;...

  • I need help putting These in correct order. Java please rearrange the following code into a...

    I need help putting These in correct order. Java please rearrange the following code into a working program based on the expected output. HINT: Use JDoodle to help in verifying the expected output 3. String D books new String 3 System.out.printinfbooks[refsl)h Int ref while (z < 3) System.out.print("books #*): books [0] "Grapes of wrath"; class BookArrays f books [1] Wind"; "Gone With The public static void main (String I ares) int z 0; 22+1; ref- title[2] int [I title new...

  • I need help solving this assignment, you are given a full piece of code that does not run correctly. Some of the bugs ca...

    I need help solving this assignment, you are given a full piece of code that does not run correctly. Some of the bugs can be found at compile time, while others are found at run time. Access the UserMenu.cpp code file (in the zip file in Start Here) and use debugging practices and the debugger in Visual Studio to find each bug. Fix the bug and write a comment in the code giving a description of how you found the...

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