Concept explainers
A)
C-String:
In C++, a declaration of an array of “char” is usually referred as “C-string”; but an array of “char” is not a C-string by itself.
- An effective C-string needs an occurrence of a terminating null character “\0”.
- No header file has required to make a C string because “char” is a built data type. Therefore, “<cstring>” file contains several functions that work on C string.
Example:
Consider the below declaration of C string variable:
Char student_name[10];
- Here the data type “char” is defined first and it is followed by the variable name “student_name”.
- The “[10]” is referred as “size declarator”. It indicates how many characters it can hold in memory cells.
Given string definition:
//definition of C-string
char name[20];
B)
C-String:
In C++, a declaration of an array of “char” is usually referred as “C-string”; but an array of “char” is not a C-string by itself.
- An effective C-string needs an occurrence of a terminating null character “\0”.
- No header file has required to make a C string because “char” is a built data type. Therefore, “<cstring>” file contains several functions that work on C string.
Example:
Consider the below declaration of C string variable:
Char student_name[10];
- Here the data type “char” is defined first and it is followed by the variable name “student_name”.
- The “[10]” is referred as “size declarator”. It indicates how many characters it can hold in memory cells.
Given string definition:
//definition of C-string
char name[20];
C)
C-String:
In C++, a declaration of an array of “char” is usually referred as “C-string”; but an array of “char” is not a C-string by itself.
- An effective C-string needs an occurrence of a terminating null character “\0”.
- No header file has required to make a C string because “char” is a built data type. Therefore, “<cstring>” file contains several functions that work on C string.
Example:
Consider the below declaration of C string variable:
Char student_name[10];
- Here the data type “char” is defined first and it is followed by the variable name “student_name”.
- The “[10]” is referred as “size declarator”. It indicates how many characters it can hold in memory cells.
Given string definition:
//definition of C-string
char name[20];
D)
C-String:
In C++, a declaration of an array of “char” is usually referred as “C-string”; but an array of “char” is not a C-string by itself.
- An effective C-string needs an occurrence of a terminating null character “\0”.
- No header file has required to make a C string because “char” is a built data type. Therefore, “<cstring>” file contains several functions that work on C string.
Example:
Consider the below declaration of C string variable:
Char student_name[10];
- Here the data type “char” is defined first and it is followed by the variable name “student_name”.
- The “[10]” is referred as “size declarator”. It indicates how many characters it can hold in memory cells.
Given string definition:
//definition of C-string
char name[20];
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
STARTING OUT WITH C++ MPL
- Lowest Score Drop Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions: void getScore() should ask the user for a test score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the five scores to be entered. void calcAverage() should calculate and display the average of the four highest scores. This function should be called just once by main and should be passed the five scores. int findLowest() should find and return the lowest of the five scores passed to it. It should be called by calcAverage, which uses the function to determine which of the five scores to drop. Input Validation: Do not accept test scores lower than 0 or higher than 100.arrow_forwardC++ Movie Data Create a program that uses a structure named MovieData to store the following information about a movie: Title Genre Director Year Released Running time (in minutes) Write a program that prompts the user for input and allows all of these member data values to be specified. Make sure you input the entire title, genre, and director for the movie. You should also make sure that the year is inputted as a number, and that the running time is also a number. For the year it should be after 1887, and for the running time the number should be greater than 0. The program should create two MovieData variables and create/use a method void displayMovie(MovieData) to display the information about the movie in a clearly formatted manner.arrow_forwardc code Screenshot and output is mustarrow_forward
- /* Program Name: BadDate.cpp Function: This program determines if a date entered by the user is valid. Input: Interactive Output: Valid date is printed or user is alerted that an invalid date was entered */ #include <iostream> bool validateDate(int, int, int); using namespace std; int main() { // Declare variables int year; int month; int day; const int MIN_YEAR = 0, MIN_MONTH = 1, MAX_MONTH = 12, MIN_DAY = 1, MAX_DAY = 31; bool validDate = true; // This is the work of the housekeeping() method // Get the year, then the month, then the day // This is the work of the detailLoop() method // Check to be sure date is valid if(year <= MIN_YEAR) // invalid year validDate = false; else if (month < MIN_MONTH || month > MAX_MONTH) // invalid month validDate = false; else if (day < MIN_DAY || day > MAX_DAY) // invalid day validDate = false; // This is the work of the endOfJob()…arrow_forwardAssume the following variables are defined: char ch; double interest ; string name ; Assign each variable to a value of the correct data type.arrow_forwardDriving costs - functions Learning Objectives Create a function to match the specifications Use floating-point value division Instructions Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 10 miles, 50 miles, and 400 miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: print(f'{your_value:.2f}') Ex: If the input to your program is: 20.0 3.1599 the output is: The gas cost for 10 miles is $1.58 The gas cost for 50 miles is $7.90 The gas cost for 400 miles is $63.20 Your program must define and call the driving_cost() function. Given input parameters driven_miles, miles_per_gallon, and dollars_per_gallon, the function returns the dollar cost to drive those miles. Ex: If the function is called with: 50 20.0 3.1599 the function returns: 7.89975 def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon) Your program should…arrow_forward
- Why is it necessary to define functions when writing code?arrow_forwardIf a program contains the definition char name[20];indicate whether each of the following lettered program statements is legal or illegal. A) cin >> name;B) cin.getline(name, 20);C) cout << name;D) name = "John";arrow_forwardProgram Requirements This program should add numbers 1 through 9 one a time, via a button click, display the result, and allow the user to Clear the total to zero. Your Starter Codeworks for numbers 1 through 3. Give it a try, push the buttons, to see what it does. Extending Structured Programs is Easy In this assignment, you use existing code to: identify the patterns in a program modify the patterns in order to extend the functionality of the program Your Task for this Assignment Requirements: Extend this program to create the 6 more HTML buttons and 6 more Javascript functions. Software Development Best Practice: Incremental Development Do not program all your code at once like you were editing some essay. Making a big mess and then trying to patch it up all one once... is a nightmare. Add one button and its function Test it Repeat with the next button Pattern One: HTML Button Add your HTML code where the highlighted area is in the image below. Copy an existing button, and…arrow_forward
- 7.Celsius Temperature Table //write code under void challenge and create function The formula for converting a temperature from Fahrenheit to Celsius is C=59(F−32)C=59(F-32) where F is the Fahrenheit temperature and C is the Celsius temperature. Write a function named celsius that accepts a Fahrenheit temperature as an argument. The function should return the temperature, converted to Celsius. Demonstrate the function by calling it in a loop that displays a table of the Fahrenheit temperatures 0 through 20 and their Celsius equivalents.\ my code below please adust and use chapter 1- 6 terminology //use only chapter 1-6 terminology!!// must validate input using do while loop examle line 98 - 108// //call functions and follow the challenge instructions//Description: Assignment6 C++ Chapter 6 #include <iostream>#include <string>#include <iomanip>#include <fstream>using namespace std; // Function prototypesint menuOption(); double getSales(string…arrow_forwardhelp me create this c++ program please Requirements: The following programming structures must be evident in your source code. Conditional structure Looping structure Array Programmer-Defined Function (do not create a header file)arrow_forwardcomputer sciencearrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT