|
|
|||||||
| Computers & Information Technologies « Everything related to computers and internet. » |
![]() |
|
|
Share | Thread Tools | Search this Thread |
|
|
#1 |
|
Registered Member
Last Online: 06-13-2011
Join Date: Jan 2007
Posts: 3,530
Thanks: 1,762
Thanked 1,429 Times in 897 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
|
First,Merry Christmas and Happy New Year.
Second,as you all know,we enter uni on the 4th of January and I have a c++ assignment in which our dr told us that is a little difficult for beginners in c++, I look at the assignment and agreed with the dr ,so i'm seeking your help here (as always ). Fa farjouna bara3etkon .================================================== ======== “Rail ticket machine” Design and implement in C++ a program that manages a rail ticket machine. The rail ticket machine functions as follows: a user selects a departure town, a destination town, a class (first or second), and a possible deduction (30%, 50%, or 60%). The rail ticket machine shows then the price of the ticket (as an integer expressed in Euros). The user inserts a sum of money as a set of coins. Four cases are then possible: 1. the sum of money is equal to the price of the ticket, the rail ticket machine delivers the ticket to the user; 2. the sum of money is greater than the price of the ticket and the rail ticket machine has enough change, the rail ticket machine returns the change and delivers the ticket to the user; 3. the sum of money is less than the price of the ticket, the rail ticket machine displays a message saying that the inserted sum is insufficient and returns the inserted money, 4. the sum of money is greater than the price of the ticket but the rail ticket machine does not have enough change, it indicates that the change is insufficient and returns the inserted money. 5. We assume that the accepted coins are in the categories 0.2, 0.5, 1 and 2 Euro. 6. We provide a table showing for two towns linked up directly by the rail the distance separating them. We also provide the price of a ticket in the first and the second class. Write an algorithm that implements the rail ticket machine. When no direct link exists between the two given towns, your algorithm should find an intermediate town so that the total distance be minimized. Your solution should manage the stock of money available in the machine in order to minimize the number of coins returned to the user. The algorithm should print a ticket containing the following information: departure town, destination tow, via town, class, deduction, price. DATA NOTE:I don't know if this is important,but ba3ed ma darasna el pointers,we only know arrays and functions and loops ,pointers ba3ed ma wsolnelon. so "GOOGLE","TAWA" and vcoderz c++ freaks i really need your help
__________________
[ |
|
|
|
|
|
#2 |
|
Last Online: 12-20-2021
Join Date: Mar 2006
Posts: 6,245
Thanks: 2,121
Thanked 3,365 Times in 1,740 Posts
Groans: 29
Groaned at 44 Times in 35 Posts
|
No, it's not difficult, you should've improved from the time we helped you last until now.
You're not learning anything if everytime you want someone to do it for you. In addition, you didn't even make an effort and showed us where you reached. // Looks like you havn't even started. Anyways, I'll look into it.
__________________
What we do in life, echoes in eternity.
|
|
|
|
|
|
#3 |
|
Last Online: 12-20-2021
Join Date: Mar 2006
Posts: 6,245
Thanks: 2,121
Thanked 3,365 Times in 1,740 Posts
Groans: 29
Groaned at 44 Times in 35 Posts
|
Code:
#include "stdafx.h"
#include <iostream>
using namespace std;
int distances[9][9] = { {-1, 560, 320, 360, 300, 555, 760, 963, -1},
{557, -1, 745, -1, -1, -1, 395, 600, 225},
{320, 750, -1, 60, -1, 760, -1, -1, -1},
{370, 780, 60, -1, 215, -1, -1, 990,-1},
{298, -1, -1, 215, -1, 800, -1, -1, -1},
{560, -1, 765, -1, -1, -1, 290, 530, 890},
{-1, 395, -1, 1034, -1, 282, -1, 237, -1},
{-1, 595, -1, -1, -1, 531, 240, -1, 580},
{785, 221, -1, -1, -1, -1, -1, 585, -1}};
char* town(int);
int distance(int, int);
int totalDistance(int[]);
void getRoute(int, int, int[]);
double price(int[], int, double);
void main(){
int a, b; // a is Source, b is Destination
int c, d; // c is Class, d is Deduction
double ded = 0;
int i;
int tab[4] = {-1,-1,-1,-1};
double money = 0;
double coin = 0;
double totalPrice;
cout << "Towns: " << endl;
for(i = 1; i < 10; i++)
cout << '\t' << i << "- " << town(i) << endl;
do{
cout << "Enter Source: ";
cin >> a;
}while(a < 1 || a > 9);
do{
cout << "Enter Destination: ";
cin >> b;
}while(b < 1 || b > 9 || b == a);
do{
cout << "Enter Class (1 for 1st, 2 for 2nd) : ";
cin >> c;
}while(c < 1 || c > 2);
do{
cout << "Enter Deduction (1 for 30%, 2 for 50%, 3 for 60%) : ";
cin >> d;
}while(d < 1 || d > 3);
if(d == 0)
ded = 0;
else if(d == 1)
ded = 0.3;
else if(d == 2)
ded = 0.5;
else if(d == 3)
ded = 0.6;
if(distance(a,b) >= 0){
tab[0] = a;
tab[1] = b;
tab[2] = -1;
}
else
getRoute(a,b,tab);
cout << "Program is: " << endl
<< "Source: " << town(a) << endl;
if(tab[2] != -1)
cout << "Station: " << town(tab[1]) << endl;
cout << "Destination: " << town(b) << endl
<< "Class: ";
if(c == 1)
cout << "1st.";
else
cout << "2nd.";
cout << endl << "Deduction: ";
if(d == 1)
cout << "30%";
else if(d == 2)
cout << "50%";
else
cout << "60%";
cout << endl << "Total Distance: " << totalDistance(tab) << endl;
totalPrice = price(tab,c,ded);
cout << "Total Price: " << totalPrice << endl;
cout << "Please Insert Coins, accepted coins are (0.2, 0.5, 1 and 2 Euro, 0 to stop): ";
money = 0;
do{
cin >> coin;
if(coin != 0.2 && coin != 0.5 && coin != 1 && coin != 2 && coin != 0)
continue;
money += coin;
}while(coin != 0);
cout << "Money entered is : " << money << endl;
}
int totalDistance(int tab[4]){
int total = 0;
int i;
for(i = 0; tab[i+1] > 0; i++)
total += distance(tab[i], tab[i+1]);
return total;
}
double price(int tab[4], int c, double d){
double s;
int totalDistance = 0;
if(c == 1)
s = 0.05;
else
s = 0.04;
int i;
for(i = 0; tab[i+1] > 0; i++)
totalDistance += distance(tab[i], tab[i+1]);
return s*totalDistance*(1-d);
}
void getRoute(int a, int b, int tab[4]){
int i;
if(distance(a, b) > 0){
tab[0] = a;
tab[1] = b;
tab[2] = -1;
}
else{
for(i = 0; i < 9; i++){
if(i == a || i == b)
continue;
if(distance(a,i) > 0 && distance(i,b) > 0){
tab[0] = a;
tab[1] = i;
tab[2] = b;
tab[3] = -1;
}
}
}
}
int distance(int a, int b){
a--;
b--;
return distances[a][b];
}
char* town(int i){
i--;
if(i == 0)
return "Paris";
else if(i == 1)
return "Bordea";
else if(i == 2)
return "Metz";
else if(i == 3)
return "Luxem.";
else if(i == 4)
return "Bruxell.";
else if(i == 5)
return "Valence";
else if(i == 6)
return "Narbon.";
else if(i == 7)
return "Barcelo.";
else if(i == 8)
return "St seb.";
return "Invalid";
}
__________________
What we do in life, echoes in eternity.
|
|
|
|
|
|
#4 |
|
Registered Member
Last Online: 01-18-2010
Join Date: Feb 2008
Posts: 4
Thanks: 0
Thanked 2 Times in 2 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
|
Tawa: I liked your first answer better
I am really against this when people go online and post their homework/assignment in full and ask for someone to do it. You are causing more harm then doing good. It would have been better if he had specific questions. That proves to me that he is trying to understand the problem. |
|
|
|
| The Following User Says Thank You to m0 For This Useful Post: | Tawa (01-18-2010) |
|
|
#5 |
|
Last Online: 05-30-2013
Join Date: Jan 2008
Posts: 1,788
Thanks: 10,018
Thanked 1,100 Times in 651 Posts
Groans: 1
Groaned at 6 Times in 6 Posts
|
Free to ask for help. Free to respond.
__________________
|
|
|
|
|
|
#6 | |
|
Last Online: 12-20-2021
Join Date: Mar 2006
Posts: 6,245
Thanks: 2,121
Thanked 3,365 Times in 1,740 Posts
Groans: 29
Groaned at 44 Times in 35 Posts
|
Quote:
it is just something he has to take.In addition, some people won't learn even if they made their own homework, and others will just lookup some exercises to learn and maybe they can learn from this one ![]()
__________________
What we do in life, echoes in eternity.
|
|
|
|
|
![]() |
|
| Tags |
| machine, rail, ticket |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|