In: Computer Science
Create a program that will prompt for user information for a Web site. Use a structure to store the data. The structure will need to include the following items:
Create a single structure from the items listed above.
Prompt for all items except "Full Name" and load the input directly into a variable based on this structure .
After the data is loaded, pass the structure by reference to a method called "loadFullName". Inside the "loadFullName" method, load the Full Name data item with a string that is a combination of First Name, space, Last Name. The full name must be converted to uppercase. After the loadFullName has executed, display the value of all the data items in the variable structure.
Review of tasks:
a. Create User Structure
b. Assign a Variable to a User Structure
b. Load the Variable Structure Data
c. Pass the Variable Structured Data to "loadFullName"
d. Display the values of the variable structure. Note: Input for a boolean var is 0 for false and 1 for true. Adding this line to display once will help display the word false or true in the output.
std::cout << std::boolalpha;
cout << "is Leasing = " << VarStrucName.isLeasingAutomobile << endl; // will display true or false - with not 0 being true
#include <iostream> #include <cstring> #include <algorithm> using namespace std; struct User { string FirstName; string LastName; string FullName; int BirthDate; bool IsLeasingAutomobile; float yearlySalary; }; void loadFullName(struct User *u) { int toupper ( int c ); cout << "First Name : " << u->FirstName << endl; cout << "Last Name : " << u->LastName << endl; cout << "Full Name: "; std::string data = u->FirstName + ' '+ u->LastName; std::for_each(data.begin(), data.end(), [](char & c){ c = ::toupper(c); }); cout<<data<< endl; cout << "Birth Date: " << u->BirthDate << endl; cout << "Is Leasing Automobile: " ; if( u->IsLeasingAutomobile == 0) { cout<<"No"<< endl; } else { cout<<"Yes"<< endl; } cout << "yearly Salary : " << u->yearlySalary << endl; } int main(){ struct User us; us.FirstName="Dhiya"; us.LastName="n"; us.BirthDate=19880412; us.IsLeasingAutomobile=1; us.yearlySalary=50000.77; loadFullName(&us); return 0; }