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
madreJ [45]
3 years ago
6

Write a function that converts a string into an int. Assume the int is between 10 and 99. Do not use the atoi() or the stoi() fu

nction.
Computers and Technology
1 answer:
Liula [17]3 years ago
6 0

Answer:

Written in C++

#include <iostream>

#include <sstream>

using namespace std;

int main()  {

   string num;

   cout<<"Enter a number: ";

   cin>>num;

   stringstream sstream(num);

   int convertnum = 0;

   sstream >> convertnum;

   cout << "Output: " << convertnum;

}

Explanation:

Without using atoi() or stoi(), we can make use of a string stream and this is explained as follows:

This line declares a string variable num

   string num;

This line prompts user for input

   cout<<"Enter a number: ";

This line gets user input

   cin>>num;

This line declares a string stream variable, sstream

   stringstream sstream(num);

This line declares and initializes the output variable, convertnum to 0

   int convertnum = 0;

The stream is passed into the output variable, convertnum

   sstream >> convertnum;

This line displays the output

   cout << "Output: " << convertnum;

<em>Note that: if user enters a non integer character such as (alphabet, etc), only the integer part will be convert.</em>

<em>For instance,</em>

<em>40a will be outputted as 40</em>

You might be interested in
Design a system for a book store that allows the owner to keep track of the store’s inventory and members. The store sells two t
IRINA_888 [86]

Hey! How are you? My name is Maria, 19 years old. Yesterday broke up with a guy, looking for casual sex.

Write me here and I will give you my phone number - *pofsex.com*

My nickname - Lovely

7 0
3 years ago
Oliver wants to send a report to his boss discussing the upcoming project. Which communication facility would he use to send a f
alina1380 [7]
To be honest, I must say email to that one.
5 0
3 years ago
Read 2 more answers
What are the most important features to consider before purchasing a PC?
leonid [27]

Answer: There are several features that should be considered before buying personal computer(PC).Some of the main factors are:-

  • Capacity of hard-drive is important to determine the storage space of the system so that it can hold data like files, videos , images etc as per the requirement.
  • RAM(Random access memory) and processor of the personal computer is important for the fast processing and execution of the tasks and functions
  • Size of the personal computer should also be considered as main feature because compact size make it portable otherwise large sized PC are bulky.
  • Brand is also a important feature because some PC and some other gadgets have already established popularity and reliability.
  • Price point is also a must because there are all types of computer available in the market from low to high cost.But the PC should be according to the budget of individual .

3 0
3 years ago
Which networking devices forward incoming data between computer networks
Gnoma [55]

Answer: C,D

Explanation:

Wireless routers are commonly found in homes -- they're the hardware devices that Internet service providers use to connect you to their cable or xDSL Internet network. A wireless router, also called a Wi-Fi router, combines the networking functions of a wireless access point and a router.

6 0
3 years ago
Read 2 more answers
Select the correct answer. Which of these is true about Eric? A. He is Leslie's character foil because he shows how vulnerable L
EleoNora [17]

Answer:

I really need the answer too,do you know what it is?

6 0
4 years ago
Other questions:
  • Assume that ip , jp , and tp have all been declared to be pointers to int and that result has been declared to be an array of 10
    13·1 answer
  • Riley needs more storage space on his small laptop, and he needs that storage to be accessible without Internet access. What is
    6·1 answer
  • How are modern computers different from eniac?
    5·1 answer
  • Which of the following is a command shell with a built-in scripting language?1. The Server Manager’s Roles and Features wizard2.
    11·2 answers
  • HELP!!! Bad things about Helen Keller. I'm doing a debate and i need to prove that Steve Jobs is better than Helen Keller!!
    14·1 answer
  • Got banned from whatsap cause I used whatsap plus what should I do pls help​
    6·2 answers
  • Question 1
    11·1 answer
  • B. What significant values have you learned while learning the tools and utensils?
    8·1 answer
  • List four types of Web browsers<br>​
    5·2 answers
  • Question 2 of 10
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!