Could anyone help me with the exam paper?

Question 1. Write an appropriate C++ statement (not a whole program) to store the salary of an employee.
Initialize it to $75,000. (Assume that the salary is capable of holding values with decimals).

double salary = 75000.00;

Question 2. Create A full C++ program to output the text of each of the months of the year on the screen.
Each month should appear on a line of its own.

Question 3. Create a C++ program to accept input from the user between the char values of A - F or lowercase a - f.
Output to the user, using "IF", "ELSE-IF", and/or "ELSE" statements what the entered value's range is in terms of numerical range i.e.
(A or a entered outputs "Your earned grade was 90.0% or greather.") Account for invalid output in the default clause.

4.The following fragment code should display like so :
[1]
[3]
[5]
[7]
[9]
[11]
Instructions are missing from the code. Write the missing instructions in its appropriate position in the code. Display a new line after each number:

int num = 0;

while ( num <= 12)
{
cout << num;
}

5.
The formula to convert Celsius temperature given a Fahrenheit temperature is below:
C° = (F° - 32) x (5 / 9) //consider the danger of integer division in your C++ formula
Create a C++ program to:
1) accept input of a Fahrenheit temperature from the user
2) Calculate the Celsius temperature only
3) Output the Celsius temperature to the screen.
4) Set the precision of the outputted Celsius variable to 4 decimal places.
Now for this one it suppose to look like the example below the only difference is the above question is only asking Calculate the Celsius temperature only....
int main()
{
double Celsius = 0.0;
double Faharenheit = 0.0;
char decision = 'A';

do
{
cout << "\nPlease enter F or C to convert tempeture. C for Celsius F for Faherenheit.\n To exit enter 0: ";
//decision = validateInt(decision);
cin >> decision;

if (decision == 'C' || 'c')
{
cout << "\nPlease enter a celcius temperature; ";
Celsius = validateDouble(Celsius);
Faharenheit = Celsius * 1.8 + 32;
cout << "\nFaharenheit is " << setprecision(4) << fixed << Faharenheit << endl;
}
else if (decision == 'F' || 'f')
{
cout << "\nPlease enter a Faharenheit tempeture: ";
Faharenheit = validateDouble(Faharenheit);
Celsius = Faharenheit - 32 * .5556;
cout << "\nCelsius is " <<setprecision(4) << fixed << Celsius << endl;
}
else
{
cout << "\nThe user did not provide a proper F or C decision" << endl;
}

} while (decision != '0');

system("pause");
return 0;
}


6.This does not have to be a complete program, but these minimum items should be included.
Standard us of the cin >> object is fine.
1) Declare a variable of type char called decision.
2) Accept input from the user for in the variable decision
3) If decision equals 'y' or if decision equals 'Y' output yes to the screen
4) otherwise If decision equals 'n' or if decision equals 'N' ouput no to the screen
5) otherwise If decision equals 'e' or if decision equal 'E' ouput exit to the screen
6) In all other cases, else, output invalid entry to the screen.
7) Put this all around a do-while loop whose exit condition is 'E' or 'e' for exit. Be sure to let the user know what the exit condition.

7. Your friend, John is used to text message communication thus when he types “I” he types it as so i …
Write a C++ program that will take John’s sentence as follows in as a string, and output instances of uppercase “I” if an instance of lowercase “i” is found in the string. The resulting string should contain the corrected instances. In all other instances, else leave the character in the case that it originally was.
The input string is: “Yesterday’s Dr. House broadcast was excellent! i am so happy! i can only wonder what House can next do.”
/*Recall that a string is an Array of Characters. Think of the built in function that enables one to capitalize a character. */

ANY ANSWER WOULD BE VERY HELPFUL! I HAVE TO SUBMIT THE ANSWERS TOMORROW!
Anyone?
Most programmers here will not solve your take-home exam for you, either due to some sense of honor preventing them from helping you cheat, or because they're corrupt but not particularly philanthropic and thus won't do it for free.

-Albatross
LOL @ the previous post! I would not be as blunt or harsh, but a word of advice for you, minbomin: a lot of the programmers on this site like to see your own input/effort first before they chip in. And trust me, there are very smart ones on here.
Last edited on
Which bit, specifically, are you having problems with?

If you post the code you've written, and give us the specifics of the problem you're having, we can help you.
closed account (48T7M4Gy)
There you go sunshine here is the answer to Q1:
1
2
3
4
5
6
/*
Todo:Write an appropriate C++ statement (not a whole program) to store the salary of an employee.
Initialize it to $75,000. (Assume that the salary is capable of holding values with decimals).

double salary = 75000.00;
*/


and, here is the answer to Q2 as a bonus:

1
2
3
4
5
6
7
8
9
#include <iostream>

int main()
{
    std::cout << "the text of each of the months of the year on the screen.\n";
    std::cout << "Each month\n";

    return 0;
}


PS I am not honorable, not philanthropic and not corrupt, but there is no charge.
Last edited on
Will this answer do?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;

int main()
{
	cout << "january" << endl;
	cout << "february" << endl;
	cout << "march" << endl;
	cout << "april" << endl;
	cout << "may" << endl;
	cout << "june" << endl;
	cout << "july" << endl;
	cout << "august" << endl;
	cout << "september" << endl;
	cout << "october" << endl;
	cout << "november" << endl;
	cout << "december" << endl;
}


Can someone give me a guidance how to do the question three? (Or even an answer would be great).
Probably will do for Q2.


Read http://www.cplusplus.com/doc/tutorial/
There are sections about "I/O" and "control structures".
Simplify your conditions by converting all input to lower (or upper) case: http://www.cplusplus.com/reference/cctype/tolower/


I object to details of Q1 and Q3.
For first, encouraging the use of non-integral types to store currency leads to the snake-pit of floating-point math.
For third, there is only an example that 'a' could correspond to "90%", but nothing is said about the other inputs. Perhaps the problem domain is implicitly and ubiquitously known in the place of exam, but since that is not true everywhere I see no problems in
IF a THEN 105% ELSE Exterminate! Exterminate!


Beware the ones that give "full solutions". The expectation is that the receiver learns nothing, fails course, drops out, and starves to death.
Alright, I have my answer now but it is not working. Please help.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>

using namespace std;

int main()
{
	char input;
	cout << "Please enter a character : "; cin >> input;

	if(input == 'a' || input == 'b' || input == 'c' || input == 'd' || input == 'e' || input == 'f' || input == 'A' || input == 'B' || input == 'C' || input == 'D' || input == 'E' || input == 'F')
	{
		if(input == 'A' || input == 'a');
		{
			cout << "Your earned grade was 90.0% or greater" << endl;
		}
		else if(input == 'B' || input == 'b');
		{
			cout << "Your earned grade was between 80.0% and 89.99%" << endl;
		}
		else if(input == 'C' || input == 'c');
		{
			cout << "Your earned grade was between 70.0% and 79.99%" << endl;
		}
		else if(input == 'D' || input == 'd');
		{
			cout << "Your earned grade was between 60.0% and 69.99%" << endl;
		}
		else if(input == 'E' || input == 'e');
		{
			cout << "Your earned grade was between 50.0% and 59.99%" << endl;
		}
		else if(input == 'F' || input == 'f');
		{
			cout << "Your earned grade was lower than 50.0%" << endl;		
		 }
	}
	else if(input != 'a' || input != 'b' || input != 'c' || input != 'd' || input != 'e' || input != 'f' || input != 'A' || input != 'B' || input != 'C' || input != 'D' || input != 'E' || input != 'F')
	{
		cout << "Invalid character!!!. . .\n";
	}
}


P.S : I only have one hour before I submit my answers. Any answer or reply would be great!
closed account (48T7M4Gy)
line 37 need only be an else statement, the condition doesn't need to be re-tested

else
cout etc etc
I am encountering compiler errors and I cannot test my code!
It continues to say that I have illegal unmatched else-if or something.
closed account (48T7M4Gy)
OK for a start remove the ; at the end of each if line
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>

using namespace std;

int main()
{
    char input;
    cout << "Please enter a character : "; cin >> input;
    
    if(input == 'a' || input == 'b' || input == 'c' || input == 'd' || input == 'e' || input == 'f' || input == 'A' || input == 'B' || input == 'C' || input == 'D' || input == 'E' || input == 'F')
    {
        if(input == 'A' || input == 'a')
        {
            cout << "Your earned grade was 90.0% or greater" << endl;
        }
        else if(input == 'B' || input == 'b')
        {
            cout << "Your earned grade was between 80.0% and 89.99%" << endl;
        }
        else if(input == 'C' || input == 'c')
        {
            cout << "Your earned grade was between 70.0% and 79.99%" << endl;
        }
        else if(input == 'D' || input == 'd')
        {
            cout << "Your earned grade was between 60.0% and 69.99%" << endl;
        }
        else if(input == 'E' || input == 'e')
        {
            cout << "Your earned grade was between 50.0% and 59.99%" << endl;
        }
        else if(input == 'F' || input == 'f')
        {
            cout << "Your earned grade was lower than 50.0%" << endl;
        }
    }
    else
    {
        cout << "Invalid character!!!. . .\n";
    }
}
Topic archived. No new replies allowed.