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
vaieri [72.5K]
3 years ago
9

Time Conversion C++: Given a time in -hour AM/PM format, convert it to military (24-hour) time.

Computers and Technology
1 answer:
mixer [17]3 years ago
8 0

Answer:

Code in C++::

#include<bits/stdc++.h>

#include<iostream>

#include<string>

#include<sstream>

using namespace std;

string timeConversion(string s){

/**

* Following two strings are declared named d and c respectively.

* String c will be storing the converted format time and we will return

* c as the answer.

*/

string d,c="";

/**

* String d stores "PM" or "AM"

*/

d=s.substr(8,2);

/**

* An integer named hr is declared below and it stores

* the hh part of string hh:mm:ssPM in integer format.

*/

int hr=atoi(s.substr(0,2).c_str());

if(hr==12 && d=="AM"){

/**

* Now suppose hr is 12 and its AM then we know that it's

* midnight and so hr must be 0.

*/

hr=0;

}

if(d=="PM" && hr!=12){

/**

* Suppose d is "PM" and hr is not 12 then we add 12 into hr.

*/

hr+=12;

}

if(hr<10){

/**

* Now suppose hr is less then 10 then we know that in final answer

* if hr is 7 then we need "07".

* So if hr < 10 then we add extra 0 at start of c string.

*/

c+="0";

}

/**

* Now we convert hr back to string using stringstream.

* A variable named hour is declared and we convert hr to string as follows.

*/

stringstream hour;

hour<<hr;

/**

* Finally we update the c string as required and return it at the end.

*/

c=c+hour.str()+s.substr(2,6);

return c;

}

int main(){

/**

* A string named s is declared and using cin we scan the string.

*/

string s;

cin>>s;

/**

* Below we call the function and pass string s as parameter.

* Whatever function returns, it is printed.

*/

cout<<timeConversion(s)<<endl;

return 0;

}

Explanation:

see thees attached

You might be interested in
Create a basic program that accomplishes the following requirements: Allows the user to input 2 number , a starting number x and
katrin [286]

Answer:

Explanation:

The following program is written in Java. It asks the user for the two inputs and then uses those inputs in a for loop. The loop goes through each number checking to see if it is even or odd. If it is even it prints out Even: and the number after multiplying it by 3. If it is odd it prints out Odd: and the number after adding 10 to it. The output can be seen in the attached picture below.

import java.util.Scanner;

class Brainly {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter number 1: ");

       int num1 = in.nextInt();

       System.out.println("Enter number 2:");

       int num2 = in.nextInt();

       for (int x = num1; x <= num2; x++) {

           if ((x % 2) == 0) {

               System.out.println("Even: " + (x*3));

           } else {

               System.out.println("Odd: " + (x+10));

           }

       }

   }  

}

6 0
3 years ago
Describe the three criteria you should use to determine if an online media source should be included in your paper or presentati
VikaD [51]
<span>To use an online resource, it should be relevant to the topic. It should be credible, coming from an expert on the topic. Finally, it should be valid, coming from a source that is based in truth or fact.</span>
7 0
3 years ago
Read 2 more answers
Given six memory partitions of 300 KB, 600 KB, 350 KB, 200 KB, 750 KB, and 125 KB (in order), how would the first-fit, best-fit,
Inga [223]

Answer:

In terms of efficient use of memory: Best-fit is the best (it still have a free memory space of 777KB and all process is completely assigned) followed by First-fit (which have free space of 777KB but available in smaller partition) and then worst-fit (which have free space of 1152KB but a process cannot be assigned). See the detail in the explanation section.

Explanation:

We have six free memory partition: 300KB (F1), 600KB (F2), 350KB (F3), 200KB (F4), 750KB (F5) and 125KB (F6) (in order).

Using First-fit

First-fit means you assign the first available memory that can fit a process to it.

  • 115KB will fit into the first partition. So, F1 will have a remaining free space of 185KB (300 - 115).
  • 500KB will fit into the second partition. So, F2 will have a remaining free space of  100KB (600 - 500)
  • 358KB will fit into the fifth partition. So, F5 will have a remaining free space of 392KB (750 - 358)
  • 200KB will fit into the third partition. So, F3 will have a remaining free space of 150KB (350 -200)
  • 375KB will fit into the remaining partition of F5. So, F5 will a remaining free space of 17KB (392 - 375)

Using Best-fit

Best-fit means you assign the best memory available that can fit a process to the process.

  • 115KB will best fit into the last partition (F6). So, F6 will now have a free remaining space of 10KB (125 - 115)
  • 500KB will best fit into second partition. So, F2 will now have a free remaining space of 100KB (600 - 500)
  • 358KB will best fit into the fifth partition. So, F5 will now have a free remaining space of 392KB (750 - 358)
  • 200KB will best fit into the fourth partition and it will occupy the entire space with no remaining space (200 - 200 = 0)
  • 375KB will best fit into the remaining space of the fifth partition. So, F5 will now have a free space of 17KB (392 - 375)

Using Worst-fit

Worst-fit means that you assign the largest available memory space to a process.

  • 115KB will be fitted into the fifth partition. So, F5 will now have a free remaining space of 635KB (750 - 115)
  • 500KB will be fitted also into the remaining space of the fifth partition. So, F5 will now have a free remaining space of 135KB (635 - 500)
  • 358KB will be fitted into the second partition. So, F2 will now have a free remaining space of 242KB (600 - 358)
  • 200KB will be fitted into the third partition. So, F3 will now have a free remaining space of 150KB (350 - 200)
  • 375KB will not be assigned to any available memory space because none of the available space can contain the 375KB process.
8 0
3 years ago
List two ways that search engines and electronic databases are similar and three ways that search engines and electronic databas
antoniya [11.8K]

Answer:

Explanation: search engine uses system algorithm to search out items or information as required by the user. Example is google, chrome.

Data base are archives where information could be retrieve. Its contain information such as publications, abstract,journals.

Search engine provides wide range of information depending on you request while database are mostly for academics related materials.

Data base- A good place to generate this information is library, archivals while journal, publiications are kept while search engine can be used anywhere you have an internet facilities.

In a data base, information is searched in an organized way. The collections are already well arranged in different cubicle search engine provides wide range of information not organized.

Data base may contain more complex information not easily understood, search engine provides more elaborate answers.

Similarity of the two is that they both provide information.

They are both reliable.

School library is an example of where journals and publication are kept and can be retrived.

6 0
4 years ago
Read 2 more answers
Hi im new and would like you to answer​
soldier1979 [14.2K]

Answer:

Explanation:yes

7 0
4 years ago
Other questions:
  • Universal Windows Platform is designed for which Windows 10 version?
    7·1 answer
  • During an experiment, if you purpose change the temperature to test a hypothesis the temperature is called what??
    6·1 answer
  • You have been asked to implement enterprise software for a manufacturer of kitchen appliances. What is the first step you should
    11·1 answer
  • Distance Traveled The distance a vehicle travels can be calculated as follows: For example, if a train travels 40 miles per hour
    15·1 answer
  • Write a user written function that expects as its input argument a vector of x values and a vector of corresponding y-values. Th
    15·1 answer
  • In the negative side of the battery, there are millions and millions of _________.
    14·1 answer
  • Three Cat 5e cables were run from an office area to three computers in a machine shop. Work took place on the weekend when the m
    14·1 answer
  • The Painting Company has determined that for every 112 square feet of wall space:
    5·1 answer
  • Consider an individual who wishes to ensure that their information remains secure and confidential, possibly to secure their per
    12·1 answer
  • A(n) ____________ calculator is a device that assists in the process of numeric calculations but requires the human operator to
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!