Hello, can someone help me to figure out what was wrong with my code? here are t
ID: 640266 • Letter: H
Question
Hello, can someone help me to figure out what was wrong with my code?
here are the assignment.
Background:
The purpose of this assignment is to get practice working with more complex problem solving. For this assignment, you'll be given a large program to write. How you do it is up to you, as long as you use functions and practice passing pass-by-reference and pass-by-value parameters. In general, there are countless ways to correctly solve a certain problem. As a programmer, eventually you should start wondering about the choices you make and which ones lead to a better solution. A number of different program dialogues demonstrate the kind of program I want you to build. Review them closely and try to build a flowchart for the questions asked and determine how the answers are processed.
Project 1: SMC Student Fees
Create a C++ program which calculates student fees for those attending Santa Monica College. IN ORDER TO RECEIVE FULL CREDIT, YOU MUST CREATE FUNCTIONS TO SOLVE THIS PROBLEM WITH BOTH PASS-BY-VALUE AND PASS-BY-REFERENCE PARAMETER (No, main() doesn't count). Summarized in the chart below is the cost calculations I want your program to perform.
SANTA MONICA COLLEGE STUDENT FEES (as of Winter, 2015)
Enrollment Fee
$ 46.00/ unit for California Residents
$ 325.00/ unit for F1/Non-Residents
Student Services Fee
(AS Sticker fee is Optional, saving $19.50)
(ID Card fee is Optional, saving $13)
$ 48.50 Winter/Summer
$ 50.50 Fall/Spring
Parking Decal (Optional)
$ 45.00 Winter/Summer
$ 85.00 Fall/Spring
A number of different program dialogues describe the program I am looking for.
SMC Fee Calculator
Enter number of units enrolled: 18
Is this Fall[0], Winter[1], Spring[2] or Summer[3] session: 0
Are you a state resident[0] or not[1]: 0
Want a parking decal? [y/n]: n
Want an AS sticker? [y/n]: n
Want an ID card? [y/n]: n
For Fall semester, your total fees are $ 846.00
SMC Fee Calculator
Enter number of units enrolled: 6
Is this Fall[0], Winter[1], Spring[2] or Summer[3] session: 1
Are you a state resident[0] or not[1]: 1
Want a parking decal? [y/n]: y
Want an AS sticker? [y/n]: y
Want an ID card? [y/n]: y
For Winter semester, your total fees are $ 2043.50
SMC Fee Calculator
Enter number of units enrolled: 18
Is this Fall[0], Winter[1], Spring[2] or Summer[3] session: 2
Are you a state resident[0] or not[1]: 1
Want a parking decal? [y/n]: y
Want an AS sticker? [y/n]: y
Want an ID card? [y/n]: y
For Spring semester, your total fees are $ 5985.50
And here is what I did.
#include <iostream>
using namespace std;
int main()
{
int unit, season, resident;
char a, b, c;
double price = 0;
cout << "SMC Fee Calculator" << endl;
cout << "Enter number of units enrolled:";
cin >> unit;
cout << "Is this Fall[0], Winter[1], Spring[2] or Summer[3] session: ";
cin >> season;
cout << "Are you a state resident[0] or not[1]:";
cin >> resident;
if (resident == 0)
{
price = 46;
}
else if (resident == 1)
{
price = 325;
}
else {
cout << "error";
}
price = price*unit;
if (season == 0 || season == 2)
{
price = price + 50.5;
}
else
{
price = price + 48.5;
}
cout << "Want a parking decal? [y/n]:";
cin >> a;
if (a == 'y'|| a == 'Y')
{
if (season == 0 || season == 2)
{
price = price + 85;
}
else
{
price = price + 45;
}
}
else{ price = price; }
cout << "Want an AS sticker? [y/n]:";
cin >> b;
if (b == 'y'|| b =='Y')
{
price = price;
}
else{
price = price - 19.5;
}
cout << "Want an ID card? [y/n]:";
cin >> c;
if (c == 'y'|| c == 'Y')
{
price = price;
}
else{
price = price - 13;
}
if (season == 0)
{
cout << "For Fall semester, your total fees are $" << price << endl;
}
else if (season == 1)
{
cout << "For Winter semester, your total fees are $" << price << endl;
}
else if (season == 2)
{
cout << "For Spring semester, your total fees are $" << price << endl;
}
else if (season == 3)
{
cout << "For Summer semester, your total fees are $" << price << endl;
}
return 0;
}
And professor said:In Order To Receive Full Credit, You Must Declare And Call Functions With Both Pass-By-Value And Pass-By-Reference Arguments. Please Correct And Re-Submit Your Homework For Full Credit. Partial Credit.
Can someone help me to correct this one?
Enrollment Fee
$ 46.00/ unit for California Residents
$ 325.00/ unit for F1/Non-Residents
Student Services Fee
(AS Sticker fee is Optional, saving $19.50)
(ID Card fee is Optional, saving $13)
$ 48.50 Winter/Summer
$ 50.50 Fall/Spring
Parking Decal (Optional)
$ 45.00 Winter/Summer
$ 85.00 Fall/Spring
Explanation / Answer
#include <iostream>
using namespace std;
void getResidance(double &price){
int resident;
cout << "Are you a state resident[0] or not[1]:";
cin >> resident;
if (resident == 0){
price = 46;
}
else if (resident == 1){
price = 325;
}
else {
cout << "error";
}
}
void getSeason(double &price, int &season){
cout << "Is this Fall[0], Winter[1], Spring[2] or Summer[3] session: ";
cin >> season;
if (season == 0 || season == 2){
price = price + 50.5;
}
else{
price = price + 48.5;
}
}
double getParking(double price, int season){
char a;
cout << "Want a parking decal? [y/n]:";
cin >> a;
if (a == 'y' || a == 'Y'){
if (season == 0 || season == 2){
price = price + 85;
}
else{
price = price + 45;
}
}
return price;
}
double getSticker(double price){
char b;
cout << "Want an AS sticker? [y/n]:";
cin >> b;
if (b == 'y' || b == 'Y'){
price = price;
}
else{
price = price - 19.5;
}
return price;
}
void getId(double &price){
char c;
cout << "Want an ID card? [y/n]:";
cin >> c;
if (c == 'y' || c == 'Y'){
price = price;
}
else{
price = price - 13;
}
}
int main()
{
int unit, season, resident;
char a, b, c;
double price = 0;
cout << "SMC Fee Calculator" << endl;
cout << "Enter number of units enrolled:";
cin >> unit;
getResidance(price); // call by reference
price = price * unit;
getSeason(price, season); // call by reference
price = getParking(price, season); // call by value
price = getSticker(price); // call by value
getId(price); // call by reference
if (season == 0){
cout << "For Fall semester, your total fees are $" << price << endl;
}
else if (season == 1){
cout << "For Winter semester, your total fees are $" << price << endl;
}
else if (season == 2){
cout << "For Spring semester, your total fees are $" << price << endl;
}
else if (season == 3){
cout << "For Summer semester, your total fees are $" << price << endl;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.