C++ Answers

Questions answered by Experts: 9 913

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

Command Line Argument - Print String

Write a program to accept a string as a command-line argument and print the same.

Sample Input (Command Line Argument) 1:

Programming


Sample Output 1:

Programming - Command Line Arguments

Sample Input (Command Line Argument) 2:

Arguments


Sample Output 2:

Arguments - Command Line Arguments


Recursion 3: Compute a^n




Write a program to compute a^n (a power n) using recursion.



Note:

Refer to the problem requirements.


Shell Scripting Function Specifications:

Use the function name as computePower() and the 2 integer arguments.

This function returns an integer value that is 'a power n'.


Function specification:

int computePower(int a,int n)



Input and Output Format:

Input consists of 2 integers.

The output is the a power n.

Refer sample input and output for formatting specifications.




Sample Input and Output:

[All text in bold corresponds to input and the rest corresponds to output.]


Enter the value of a

2

Enter the value of n

8


The value of 2 power 8 is 256


Many programming languages, especially older ones, provide no language support for concurrency. C and C++ are examples of such languages. Is it essential that a language include syntax for concurrency to be able to write concurrent programs in that language? If not, how is it accomplished? What are the advantages and disadvantages of including support for concurrency in a language?


Three employees in a company are up for a special pay increase. You are given a file, say Ch3_Ex5Data.txt, with the following data:

Miller Andrew 65789.87 5
Green Sheila 75892.56 6
Sethi Amit 74900.50 6.1

Each input line consists of an employee’s last name, first name, current salary, and percent pay increase.

For example, in the first input line, the last name of the employee is Miller, the first name is Andrew, the current salary is 65789.87, and the pay increase is 5%.

Instructions

Write a program that reads data from a file specified by the user at runtime (i.e. your program should accept the filename as user input) and stores the output in the file Ch3_Ex5Output.dat. To test your program, use the Ch3_Ex5Data.txt file.

Your program will not pass all checks if it does not accept a filename as input from the user.

For each employee, the data must be output in the following form: firstName lastName updatedSalary.







A box of cookies can hold 24 cookies, and a container can hold 75 boxes of cookies.

Write a program that prompts the user to enter:

  • The total number of cookies

The program then outputs:

  • The number of boxes and the number of containers to ship the cookies.

Note that each box must contain the specified number of cookies, and each container must contain the specified number of boxes. If the last box of cookies contains less than the number of specified cookies, you can discard it and output the number of leftover cookies.

Similarly, if the last container contains less than the number of specified boxes, you can discard it and output the number of leftover boxes.


Suppose that billingAmount is a double variable, which denotes the amount you need to pay to the department store. If you pay the full amount, you get $10.00 or 1% of the billingAmount, whichever is smaller, as a credit on your next bill; If you pay at least 50% of the billingAmount, the penalty is 5% of the balance; If you pay at least 20% of the billingAmount and less than 50% of the billingAmount, the penalty is 10% of the balance; otherwise the penalty is 20% of the balance. Design an algorithm that prompts the user to enter the billing amount and the desired payment. The algorithm then calculates and outputs the credit or the remaining balance. If the amount is not paid in full, the algorithm should also output the penalty amount.

Since your program handles currency, make sure to use a data type that can store decimals with a precision to 2 decimals.





Given a highway number, indicate whether it is a primary or auxiliary highway. If auxiliary, indicate what primary highway it serves. Also indicate if the (primary) highway runs north/south or east/west.


Write a Program: Print a table of stars and zeroes

print a square table of alternating stars and zeroes.


Ask the user to enter a size of the table. The number should be odd. Since the table is square the number of rows and columns will be the same and should be equal to the entered size. The valid range for the size is from 3 to 15, inclusive.


Use a loop to make sure the entered size is odd and within the range. Output a descriptive error message if an invalid size is entered. The error message should indicate if the size is even, or less than the minimum, or larger than the maximum.


If more than one error condition appears. Don't create separate output strings for all combinations of error conditions


Each row in said table should have ‘*’ and ‘0’ symbols separated by a space. Each column of the table should also have alternating ‘*’ and ‘0’ symbols. All corners should have the ‘*’ symbol.





Write a program to create a class called STUDENT with data members Roll

Number, Name and Age. Using inheritance, create the classes

UGSTUDENT and PGSTUDENT having fields a semester, fees and

stipend. Enter the data for at least 5 students. Find the average age for all

UG and PG students separately.


(Multipath Inheritance) Design a base class called Student with two

fields:- (i) Name (ii) roll number. Derive two classes called Sports and

Exam from the Student base class. Class Sports has a field called s_grade

and class Exam has a field called e_grade which are integer fields. Derive a

class called Results which inherit from Sports and Exam. This class has a

character array or string field to represent the final result. Also it has a

member function called display which can be be used to display the final result.Illustrate the usage of these classes in main.


LATEST TUTORIALS
APPROVED BY CLIENTS