1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
nordsb [41]
3 years ago
14

Write a C program that reads a time from the keyboard. The time should be in the format "HH:MM AM" or "HH:MM PM". Hours can be o

ne or two digits, minutes are exactly two digits, and AM/PM can be in any mixture of uppercase and lowercase. For example, "1:10 am", "12:05 PM", and "12:45 aM" are valid inputs. Your program should include a function that takes a string parameter containing the time. This function should convert the time into a four-digit military time based on a 24-hour clock. For example, "1:10 AM" would output "0110 hours", "11:30 PM" would output "2330 hours", "12:15 AM" would output "0015 hours", and "5:05 Pm" would output "1705 hours". The function should return a string to be written to the screen by the main function
Computers and Technology
2 answers:
Alecsey [184]3 years ago
5 0

Answer:

See explaination

Explanation:

#include <iostream>

#include <stdio.h>

#include <string>

#include <cctype>

#include <stdlib.h>

#include <sstream>

using namespace std;

string itoa(int num)

{

stringstream converter;

converter << num;

return converter.str();

}

string convert(string str){

size_t pos = str.find_first_of(':');

string hour = str.substr(0,pos);

string min = str.substr(pos+1,2);

string ampm = str.substr(pos+4,2);

int h = atoi(hour.c_str())%12;

if(ampm == "pm" || ampm == "Pm" || ampm == "PM" || ampm == "pM")

hour = itoa(h+12);

else if(h == 0)

hour = "00";

else if(h<10)

hour = "0" + hour;

string mtime = hour + min;

return mtime;

}

int main() {

string ntime;

cout<<"Enter time: ";

getline(cin,ntime);

cout<<"Corresponding military time is "<<convert(ntime)<<" hours";

return 0;

}

wolverine [178]3 years ago
4 0

Answer:

Check the explanation

Explanation:

C++ code:

#include <bits/stdc++.h>

using namespace std;

string convert(string s){

  int l=s.length();

  string ans=" hours";

  if(l==7){

      if(s[5]=='a'||s[5]=='A'){

          ans[0]='0';

          ans[1]=s[0];

          ans[2]=s[2];

          ans[3]=s[3];

else{

      if(s[6]=='a'||s[6]=='A'){

          ans[0]=s[0];

          ans[1]=s[1];

          ans[2]=s[3];

          ans[3]=s[4];

  return ans;

}

int main(){

  cout<<"Enter time: ";

  string s;

  getline(cin,s);

  cout<<"Corresponding military time is "<<convert(s)<<endl;

return 0;

}    

You might be interested in
Publishing is copying Web pages and associated files to a Web<br> server. T or f
sineoko [7]
The answer would be true.
4 0
3 years ago
What are the values of the following expressions? In each line assume that,
MissTica

Answer:

double x = 2.5;

double y = -1.5;

int m = 18;

int n = 4;

string s = "Storm";

string t = "Watch";

The output of the expression "x + n*y - (x+n)*y" is "6.25".

and the output of expression "m/n + m%n" is "6".

Explanation:

for the first expression,

x + n*y - (x+n)*y ,put value of every variables in it.

=2.5+4*(-1.5)-(2.5+4)*(-1.5)

=2.5-6.0-(6.5*(-1.5)

=-3.5+9.75

=6.25

for the second expression,

m/n + m%n,  put value of every variables in it.

=18/4 +18%4

=4+2      ("/ will give quotient and % will give remainder")

=6

4 0
4 years ago
Characteristics of the printer​
sveticcg [70]
Important printer characteristics include resolution, speed, color, and cache memory.
4 0
3 years ago
An online retailer is looking to implement an enterprise platform. Which component of the enterprise platform will help the comp
adelina 88 [10]

Answer: Data and Insights

Explanation:

Data and Insights in an enterprise platform is very important as it helps users better understand their customers so that they may be able to offer them the best services.

Data allows the platform to capture the data of the customer and insights then curates and consumes the data for analysis. The result of this analysis will enable the company to better understand the customer so that they might be able to offer preferable products.

3 0
3 years ago
You have probably heard of wearable fitness devices, such as FitBit. What new products do you think might exist in this field in
tino4ka555 [31]

The new products in this fitness field in a decade are:

  • TRX Home2 System.
  • Rogue Rubber Coated Kettlebells.
  • Stamina Adjustable Kettle Versa-Bell, etc.

<h3>What is the use of artificial intelligence in fitness?</h3>

AI is known to be in the field of wellness and also fitness as it has made product such as:

  • GOFA Fitness that uses GPS.
  • 3D motion tracking technology.
  • Machine learning to give users with live feedback when in a workouts, etc.

Therefore, The new products in this fitness field in a decade are:

  • TRX Home2 System.
  • Rogue Rubber Coated Kettlebells.
  • Stamina Adjustable Kettle Versa-Bell, etc.

Learn more about fitness from

brainly.com/question/1365564

#SPJ1

5 0
3 years ago
Other questions:
  • Outline a scenario in which you might be acting ethically but might still want to remain anonymous while using the Internet. How
    14·1 answer
  • What effects will the different types of lighting produce on mountains?
    15·1 answer
  • An authenticated user can add up to how many computer accounts to the domain, by default
    6·1 answer
  • Is backing up computer files done on the hard drive?
    5·1 answer
  • Which of the acronyms listed below refers to a series of basic hardware diagnostic tests performed by the startup BIOS after the
    13·1 answer
  • How do I change the selected cell to 20 pt
    8·2 answers
  • Write a program that scores a blackjack hand. In blackjack, a player receives from two to five cards. (The player decides how ma
    5·1 answer
  • Adjust list by normalizing When analyzing data sets, such as data for human heights or for human weights, a common step is to ad
    7·1 answer
  • After you have located a program name from the Start menu, in order to create a shortcut on the desktop.
    8·1 answer
  • What if you accidentally delete your browser history
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!