Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i have a C++ lab where i have to ask the user for their names using strings, (first and last name) and then display how

i have a C++ lab where i have to ask the user for their names using strings, (first and last name) and then display how many letters are in their name. then ask the user for dimensions for a cylinder to which it will then calculate the mass and volume. Ive included the code ive got so far ( not all is working) but the things inside show the basis of what im allwoed to use and cant really go to much more advanced than that. ive also added the lab itself as well as the format the code NEEDS to look like ( or at least very similar too) when run. can you help me out? thanks.

Note Getname, getflaot, Mass, and volume all need to be seperate functions.

THE CODE SO FAR:

#include #include #include #include

#define _CRT_SECURE_NO_WARNINGS

/******************************************************************************* LAB 2: Using Functions ******************************************************************************** Developed by: Date: Jan 14, 2020 ******************************************************************************** Description: *******************************************************************************/ //Function prototype void purpose(); void GetName(char FnName[]); float GetFloat(char value[]); float Volume(char Radius[], char Height[]); /******************************************************************************* Main *******************************************************************************/ void main() {

//Variable Declarations/user inputs purpose(); //print the message char FName[11] = "first"; char LName[11] = "last"; char value[20] = "radius (m)"; float massOfCylinder; float volOfCylinder; float Radius, Height, Density; GetName(FName); GetName(LName); Radius = Getfloat (value); strcpy(value, "Height (m)"); Height = GetFloat (value); strcpy(value, "Density (kg/m cubed)"); Density = GetFloat (value);

while (!_kbhit());

}

/******************************************************************************* Purpose - This function prints the purpose of the program to the console.

Inputs: none

Returned: none *******************************************************************************/ void purpose(void) { printf(" This program will ask for the users first name and last name "); printf(" and tell you how many letters are in your name. "); } /******************************************************************************* GetName - This function requests the Name of the user and returns it to the calling function.

void GetName(char FnName[]) { //First Name printf(" Please enter your %s name: ", FnName); fflush(stdin); fgets(FnName, 11, stdin); } /******************************************************************************* GetFloat - Gets the values from user *******************************************************************************/ float GetFloat(char value[]) { float number(); //Gets the radius from user printf(" please enter %s: ", value); fflush(stdin); fgets(number, 11, stdin); return; }

*************************************

image text in transcribedimage text in transcribedimage text in transcribed

Create a main that will use functions to: a. explain the purpose to the user b. get the user's first and last names C. calculate the number of characters in each name d. calculate the volume of a cylinder e. calculate the mass of fluid in a cylinder 2. Write a function, called Purpose, that will explain the purpose of the program to the user. Write a function, called GetName, that will ask the user for a name. This function will be called twice, once for their first name and once for their last name. Limit the array to 10 characters (this does not include a NULL). Entered characters exceeding 10 should not overwrite surrounding memory, i.e. use the fgets() function. This function should also return the number of characters in the name. Note: fgets appends a ' ' at the end of the string. You will need to replace this with '\0' for formatting purposes. Hint: the strcspn() function works well for this. Write a function, called GetFloat, that will get a floating point number from the user and return it to the calling function. This function will require the name of the float to be passed to the function. For example, if radius is desired, send the string radius to the function. This will be used to specify to the user which value is being requested. Write a function, called Volume, that will calculate and return the volume of a cylinder (in m3). The function requires the cylinder radius (in m) and height (in m) as inputs. 6. Write a function, called Mass, that will calculate and return the mass of fluid (in kg) in a cylinder. The function requires the cylinder volume (in m3) and density (in kg/m3) as inputs. 7. Main should also display the following output to the user, note that your display should appear exactly as follows (with your values inserted in place of the bold italicized variables): user_first_name user_last_name, there are x letters in your first name and x letters in your last name. Based on the cylinder dimensions and fluid density you entered, height = X.XX m, radius = X.XX m, density = X.XX kg/m^3, volume = x.x m^3 and mass = x.x kg, when full

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

How your project links to your business strategy

Answered: 1 week ago