Concept explainers
To input the user's name and the Social Security Number and print the details in different formats.
Explanation of Solution
Program:
#include <iostream> usingnamespace std; intmain() { stringfname, lname; // string declared for the first name and the last name intssn; // integer declared for the Social Security Number cout<<"Enter your first name:\n"; cin>>fname; cout<<"Enter your last name:\n"; cin>>lname; cout<<"Enter your Social Security Number:\n"; cin>>ssn; cout<<"Your details are:\n"; // details will be printed in different formats. cout<<ssn<<", "<<fname<<", "<<lname<<endl; cout<<ssn<<", "<<lname<<", "<<fname<<endl; cout<<lname<<", "<<fname<<", "<<ssn<<endl; return 0; }
Explanation:
An 'iostream' is a header file or a pre-defined file in which cin and cout is defined.
To use the header files in the program, keyword include is written before the header file name surrounded with angular brackets.
The include keyword is always written after the '#', which is known as a preprocessor.
A preprocessor means something is being processed before the program. A preprocessor shows that the header files are processed before the program.
A 'using' is a keyword used to specify namespace or file is used with the program.
A ' namespace' is typically a container for a collection of identifiers. A namespace provides a degree of context for different identifiers, making it possible to differentiate identifiers with the same name.
C++ transferred all the standard library's features to a namespace called "std" (standard).
The cout is the keyword used to print a message or a value to the user or on the screen.
The cin keyword takes input from the user.
A main is the default name given to the main function of a program where the return type means function should return some value, here return type int is given.
In a program, the return type of the main function is int, that is, it should return an integer value. The return is considered as the exit status of an application.
Sample Output:
Want to see more full solutions like this?
Chapter 4 Solutions
PROGRAM+PROBLEM SOLVING W/C++,BRF (SPEC
- You can write a program in C++ using only one function. At the same time you can break this function into 20 smaller functions calling each other. Which approach is better? Why?arrow_forwardHello. I need help with a dice roller program in C++. The program compiles and mostly works, but for negative numbers, I want to just print Illegal value entered. But it also prints the rolling and total, which I should only show with positve numbers not negative numbers. How do I stop the function when a negative number is entered and move on to the next function?arrow_forwardQUESTION: Write a C++ program that will ask user to input integer and it will display a magic square in a row and column format. Magic square a square containing a number of integers arranged so that the sum of the numbers is the same in each row, column, and main diagonal and often in some or all of the other diagonals.arrow_forward
- In C++ could someone help me with this? you will see the main program must read from the file shownarrow_forwardwrite a c++ code, please test itarrow_forwardPLEASE SOLVE THIS IN C++ CODE ONLY! PLEASE READ AND DO THE PROGRAM WITH ACCORDING TO THE CONDITIONS GIVEN. PLEASE ALSO WRITE THE USE OR FUNCTIONS OF EACH CODE USED BY INSERTING ITS USE EVERY LINE USING "//" A palindrome is a string that reads the same from front to back as it does from back to front, e.g., "racecar", "radar", "21012". Write a program that will identify whether a given line of input is a palindrome or not. Your program must also be able to determine the following sample inputs as palindromes, aside from identifying one-word inputs: Able was I 'ere I saw Elba. Madam, I'm Adam. A man, a plan, a canal, Panama. These samples require that your program must ignore spaces and punctuations, and consider uppercase and lowercase letters to be the same. Include necessary functions in your program to process the input. You can also use existing functions from the string library.arrow_forward
- The question should be done in C++, please give explanation and running result. 1. Let’s write a function that compares 2 strings and returns true if they were identical, false otherwise. The signature of this function should be: bool word_diff(std::string word1, std::string word2); For example: std::string str1 = "Hello World";std::string str2 = "hEllO World";std::string str3 = "World";std::string str4 = "Hello World";bool result = word_diff(str1, str2); // Falsebool result = word_diff(str1, str3); // Falsebool result = word_diff(str1, str4); // True 2. Now let’s follow a classical approach to compare the content of 2 files. We should open each file, read their content word by word and compare them until a first mismatch occurs.Let’s implement a function called classical_file_diff that takes 2 arguments each of which is a file name and returns a boolean indicating whether the 2 files are identical or not. The signature of this function should be: bool…arrow_forwardSir help me I am trying to print something in c but I getting error printf is not defined. I included the print in main function. Help mearrow_forward(Practice) Write C++ statements for the following: a.b=sinxcosxb.b=sin2xcos2xc.area=( cbsina)/2d.c= a 2 + b 2 e.p= | mn|f.sum= a( r n 1) r1arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning