2.
Assume that each of the following statements applies to the same program.
a.
Write a statement that opens file
oldmast.dat
for
input; use an ifstream object called
inOldMaster.
b.
Write a statement that opens file
trans.dat
for reading
and writing data to it; use fstream object
transFile
that can read data from the file trans.dat
as well as write data to it.
c.
Write a statement that writes a record to the transfile. The record to store consist of an integer data
accountNumber
, and a floating point data
dollarAmount
Find the error(s) and show how to correct it(them) in each of the following.
a.
File
pets.dat
that stores its id, name, age and owner
of the pet is referred to by ofstream object
petfile
.
petfile>>pet_id>>pet_name>>pet_age>>pet_owner;
b.
The following statement should create an ifstream object
salesfile
that refers to the file
weeklysales.dat
that contains data about the id the
salesperson, total sales generated, and the
week number, read the data from the file and display it on the console output.
ifstream salesfile(“weeklysales.dat”);
int id,wk;
float sales;
salesfile>>id>>wk>>sales;
while (!salesfile.eof()){
cout<<id<<”\t”<<sales<<”\t”<<wk<<”\n”;
salesfile<<id<<wk<<sales;
}
Write a program with three functions that calculates the final purchase price after various promotions and sales tax are applied. All functions will use Pass by Reference to manipulate the total purchase price. The functions are described below:
Function #1 = Take 20% off the price
Function #2 = Take an addition $10 off ONLY if the current total is at least $50 (after function #1)
Function #3 = Apply 7% sales tax to the total after function #2
Output:
Enter the total price of your purchases: [user types: 100]
The final price of your purchase including all promotions and tax is: $74.90
Write a program with three functions that all use the same global constant. The global constant is the name of a video game: "Fun With Math 2". Each of the functions should output a message that contains this global constant. There is one intro message, one game-exit message, and one game completion message.
Output:
Welcome to Fun With Math 2
This program aims to improve your math skills via interactive games.
Thank you for playing Fun With Math 2
Remember to practice daily!
You have successfully completed all of the activities in Fun With Math 2
Be sure to look out for the 3rd edition of this game (Coming in Summer 2049)!
Create a rectangle class having length and width as parameter. Write getter/setter for
each parameter. Write default constructor that should initialize the default value to the
length and width.. Write member functions to calculate area and another function to
calculate perimeter in class. Write a function to print the information regarding rectangle
which include length, width, area and parameter.
Formula to calculate area = 0.5 * length * width
Formula to calculate perimeter=2 * length+ 2 * width
A code is required to print all possible arrangement of combination of an array(of 'k' elements), i.e. the permutation of the result of combination.
Let's say the array has the following elements (k=4):
"alpha", "beta", "gamma", "delta".
Then, we choose r=3
The expected result is as follows:
alpha beta gamma
alpha gamma beta
beta alpha gamma
beta gamma alpha
gamma alpha beta
gamma beta alpha
alpha beta delta
alpha delta beta
beta alpha delta
beta delta alpha
delta alpha beta
delta beta alpha
alpha delta gamma
alpha gamma delta
delta alpha gamma
delta gamma alpha
gamma alpha delta
gamma delta alpha
beta delta gamma
beta gamma delta
delta beta gamma
delta gamma beta
gamma beta delta
gamma delta beta
From the above result above, all unique PERMUTATION of the COMBINATION of r=3 from the array of k=4 elements is completed.
This is confirmed since 4C3 x 3! = 24 lines of results
Write a program to find length of string by using pointers
Make a function which take a array which store 10 students cgpa. Find the the highest cgpa of student in the array.
Make a function which take an integer array and return sum of all even values.
(Note: Make array of 10 size in the main function)
write a program in c++ to get two numbers and the operators from user:
1 if the operator is + then display sum the sum of two numbers,