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
Please i need your help
motikmotik
Hello!

The answer would be:

C. non-linear navigation.

Explanation: Non-linear navigation lets a user navigate through material without them having to follow a strict order.

I hope that this helps you!
3 0
2 years ago
Which type of classroom enables students to attend lectures without being physically present with the teacher?
Kisachek [45]
An online class? I think lol
5 0
4 years ago
Which of the following is a trend that began during the Vietnam War and continued with the Internet?
Blizzard [7]
<span>As far as I remember, this one - a. a move toward stricter control of mass-media communications by Congress and the FCC </span><span>is a trend that began during the Vietnam War and continued with the Internet.</span>
7 0
3 years ago
Define watcher block
DochEvi [55]

Answer:

Happens when you are watching a series / film / drama / etc. but can not retain the attention span to watch for long periods of time. As well as the shortened viewing time, the ability to retain what has been viewed is impaired.

Explanation:

5 0
3 years ago
Read 2 more answers
Design the logic for a program that allows a usher to continuously enter numbers until the usher enters 0. Display the sum of th
uysha [10]

int sum = 0, n;

do {cin>>n; sum+=n;}while (n!=0);

cout<<sum;

5 0
4 years ago
Other questions:
  • Your revenue is $22,000. Your Cost of Goods is 16,250. Your gross profit is _____________, fill in the blank,.
    14·1 answer
  • Describe a scenario for which a find unmatched query could be used.
    12·1 answer
  • Which of the following cannot be copyrighted?
    10·1 answer
  • What unit is used to describe the smallest amount of bitcoin?
    13·1 answer
  • What is Game Theory?
    6·1 answer
  • Which of these are variables in an organization? Choose three.
    9·1 answer
  • The force required to slide an object is equal to _____.
    13·1 answer
  • Ventajas y desventajas de la prevención de descargas​
    13·1 answer
  • .
    5·1 answer
  • What is the hack of the cookie clicker
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!