Concept explainers
Implementation of a program with typical sections
Program Plan:
Write a C++ program with a main function and the required set of statements to accomplish the following:
Write C++ statements that include the header files iostream and string
Write a C++ statement that allows you to use cin, cout, and endl without the prefix std::.
Write C++ statements that declare the following variables: name of type string and studyHours of type double
Write C++ statements that prompt and input a string into name and a double value into studyHours
Write a C++ statement that outputs the values of name and studyHours with the appropriate text. For example, if the value of name is "Donald" and the value of studyHours is 4.5, the output is,
Hello, Donald! on Saturday, you need to study 4.5 hours for the exam.
Compile and run your program
Trending nowThis is a popular solution!
Chapter 2 Solutions
C++ Programming: From Problem Analysis To Program Design, Loose-leaf Version
- in c++ Write a program to generate a random number between 1 - 100, and then display which quartile the number falls in. First quartile is 1 - 25 Second quartile is 26 - 50 Third quartile is 51 - 75 Fourth quartile is 76 - 100 To generate a random number, follow these steps: include necessary header files #include <cstdlib> //for random functions #include <ctime> //for time functions set constants for the minimum and maximum values of the desired range const int MIN_VALUE = 1; //minimum range value const int MAX_VALUE = 100; //maximum range value seed the random number generator (RNG) with a unique unsigned int value - system time! unsigned seed = time(0); //system time in seconds since 1/1/1970 srand(seed); //seed the RNG get a random number in the desired range int num = (rand() % (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE; The program should: contain header comments as shown in class display a "hello" message (more descriptive than shown in sample)…arrow_forwardExercise #3: Character Counts Write a c++ program that prompts the user to enter a string, calls the function lowerUpperDigits( ) which takes a string and counts the number of lower, upper, and digit characters in the string. The main program prints the number of found characters. int lowerUpperDigits(string, int&, int&); Sample input / output:arrow_forward4. A user enters an email address in a string variable in C++. Write a program that displays whether the email address contains any digit or not.arrow_forward
- C++arrow_forwardc++ problemarrow_forwardC++ Programming I Program 4: C++ Craps Game Functions in files, random numbers , stringstream and precision Craps is a popular dice game played in casinos. The C++ variation is as follows: Make a bet. Roll two dice. Each die has six faces, representing values 1-6. Check the sum of the faces showing on the two dice.: If the sum is 2, 3 or 12 (craps), you lose. If the sum is 7 or 11 (natural), you win. If the sum is anything else, a point is established (the sum of the dice you rolled) and you continue to roll until you re-roll the point (you win) or you roll a 7 (you lose). This program will contain 6 functions to be called from main and from another function. The functions will be contained in two files: Functions.h, which contains the function prototypes, and Functions.cpp, which will contain the function implementations (or bodies). Do not forget to put include guards in the Functions.h file. Begin the program by declaring variables…arrow_forward
- #include <stdio.h>#include <string.h> #pragma warning(disable : 4996) // compiler directive for Visual Studio only // Read before you start:// You are given a partially complete program. Complete the functions in order for this program to work successfully.// All instructions are given above the required functions, please read them and follow them carefully. // You shoud not modify the function return types or parameters.// You can assume that all inputs are valid. Ex: If prompted for an integer, the user will input an integer.// You can use only the strlen() of strings.h library to check string length. Do not use any other string functions // because you are supposed to use pointers for this homework. // **** DO NOT use arrays to store or to index the characters in the string **** // Global Macro Values. They are used to define the size of 2D array of characters#define NUM_STRINGS 4#define STRING_LENGTH 50 // Forward Declarationsvoid…arrow_forwardc++arrow_forwardC++arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education