100% tevredenheidsgarantie Direct beschikbaar na betaling Zowel online als in PDF Je zit nergens aan vast
logo-home
main.c code €31,53   In winkelwagen

Overig

main.c code

 23 keer bekeken  1 keer verkocht
  • Vak
  • Instelling

main.c is made of different functions and arrays. It must be executed with the headers files, (colours.h) and (global_variables.h) The Car Sales project must make its output to the Console (i.e. the Command Prompt using printf) and it must exhibit the following features as a minimum: 5%: Loo...

[Meer zien]

Voorbeeld 3 van de 24  pagina's

  • 24 februari 2023
  • 24
  • 2022/2023
  • Overig
  • Onbekend
  • Onbekend
avatar-seller
// https://github.com/kaloyannt
//THIS PROJECT IS LISTED ON MY GITHUB PROFILE

//We are using _CRT_SECURE_NO_WARNINGS in order to be able to use (scanf)
#define _CRT_SECURE_NO_WARNINGS
SetConsoleOutputCP(CP_UTF8);

#include <stdio.h> //<--- External headers
#include <stdlib.h> //<--- External headers
#include <string.h> //<--- External headers
#include <conio.h> //<--- External headers

/*Colours will be used to enhnance the user experience
and provide guidance. For example Green (Success); Red
(Error); Yellow (Information) .. https://www.theurbanpenguin.com/4184-2/ */
#include "colours.h" // <--- This is my own header, located as a seperate file.

//This is the header, where I store all my global variables that I need access
anywhere
//In the program.
#include "global_variables.h" //<--- This is my own header, located as a seperate
file.

void files() {
//NAMING THE FILES POINTERS
FILE* sales_data; FILE* payment_details;

//OPENING THE FILES
//WE HAVE TO OPEN THE FILES WAY BEFORE THE PROGRAM BEGINS, TO ENSURE THAT
//WHEN THE SALES PAGE IS OPEN, THE PROGRAM DOES NOT CRASH
//THE PROGRAM WILL LOOK FOR THOSE FILES AND IF THEY DO NOT EXIST, IT WILL
THROW AN ERROR.
//Source: https://www.guru99.com/c-file-input-output.html
//"append mode. If a file is in append mode, then the file is opened. The
content within the file doesn’t change."
sales_data = fopen("sales_data.txt", "a"); payment_details =
fopen("payment_details.txt", "a");
fclose(sales_data); fclose(payment_details);
}

//Pauses the program function
void pause_program() {
char pause;
scanf("\n%hd\n", &pause);
}

//Clear program screen function
void clearScreen() {
system("cls");
}

//Allows user to return to the main menu
void back_to_menu() {
printf("Enter (y) to return to the menu -- (n) to exit the program.\n");
char backinput;
//Filter user Input
//This is used at the end of every purchase, to allow the user to return to the
menu.
fscanf(stdin, "\n%c", &backinput);

, if (backinput == 'y') {
//If their input is equal to y, execute the function below
//Take user back to the main menu.
main();
clearScreen();
}
//If their input is equal to n, execute the code below:
else if (backinput == 'n') {
exit(1);
}
//If their input is not matching n or y, then execute the code below:
else {
printf("Sorry, invalid option");
}
}

//Main main, present user with 3 options to choose from.
int show_menu() {
reset();
clearScreen();
printf(":----------------------------------:\n");
yellow();
printf(": M A I N M E N U :\n");
reset();
printf(":----------------------------------:\n");
printf(":----------------------------------:\n");
printf(": Please select an option :\n");
printf(": 1. Buy Cars :\n");
printf(": 2. View sales Data :\n");
printf(": 3. View Cars Stock :\n");
printf(": 4. Admin :\n");
printf(":----------------------------------:\n");
printf(": Welcome to MOD003212 Car Sales :\n");
green();
printf(": Software author: Kaloyan Titov :\n");
reset();
printf(": Local time @%s :\n", __TIME__);
cyan();
printf(": https://github.com/kaloyannt :\n");
reset();
printf(":----------------------------------:\n");

//\n (new line) in order to ignore my previous input of y or n and allow me
to enter a new input.
printf("Option /> "); scanf("\n%c", &menu_option);
}

//Show cars Available
//This function, will be used to reset and set the stock,
//Every time when the program is closed and re-opened.
int carsAvailable() {

//Naming the file
FILE* carsAvailable;
//Creating the file, before the program executes.
carsAvailable = fopen("carsAvailable.txt", "w");

//Writing the amount of cars declared to the file.
fprintf(carsAvailable, "%d", setCarStock); // <-- This variable contains the

, amount of stock to write to the file.
// The setCarStock variable is stored in global_variables.h file.

//Closing the file
fclose(carsAvailable);

//Opening the file again, but to read this time.
carsAvailable = fopen("carsAvailable.txt", "r");

//Creating a new int variable named scanCarsAvailable, to scan the contents
of the file and put them
//Into the variable named cars
unsigned long cars;
int scanCarsAvailable = fscanf(carsAvailable, "%d", &cars);

//If variable cars (which contains the number from the file) is more than 0
//Run the code below:
if (cars > 0) {
printf("%d", cars);
}
//If is less than 0, then display that there is no more stock;
else {
printf("No more cars available");
}
//Close the file again
fclose(carsAvailable);
}

//This would update the GLOBAL stock, once any purchase has been made.
int updatedGlobalStock() {
//Updating the global car stock, when a car model is purchased.
//This is a arithmetic calculation that will updated the stock
//Accordingly, depending on how many cars have been brought for each brand.
//The stock will be updated globally in the program.
setCarStock -= carsNeededMercedes;
setCarStock -= carsNeededAudi;
setCarStock -= carsNeededToyota;
setCarStock -= carsNeededPorsche;
setCarStock -= carsNeededBmw;
}

/*This is the purchase screen that the user is presented with, once
They have selected the model number "101" */
int purchaseScreenMercedes() {


//NAMING THE FILES POINTERS
FILE* sales_data; FILE* payment_details;

//OPENING THE FILES
//WE HAVE TO OPEN THE FILES WAY BEFORE THE PROGRAM BEGINS, TO ENSURE THAT
//WHEN THE SALES PAGE IS OPEN, THE PROGRAM DOES NOT CRASH
//THE PROGRAM WILL LOOK FOR THOSE FILES AND IF THEY DO NOT EXIST, IT WILL
THROW AN ERROR.
//Source: https://www.guru99.com/c-file-input-output.html
//"append mode. If a file is in append mode, then the file is opened. The
content within the file doesn’t change."
sales_data = fopen("sales_data.txt", "a"); payment_details =
fopen("payment_details.txt", "a");

Voordelen van het kopen van samenvattingen bij Stuvia op een rij:

Verzekerd van kwaliteit door reviews

Verzekerd van kwaliteit door reviews

Stuvia-klanten hebben meer dan 700.000 samenvattingen beoordeeld. Zo weet je zeker dat je de beste documenten koopt!

Snel en makkelijk kopen

Snel en makkelijk kopen

Je betaalt supersnel en eenmalig met iDeal, creditcard of Stuvia-tegoed voor de samenvatting. Zonder lidmaatschap.

Focus op de essentie

Focus op de essentie

Samenvattingen worden geschreven voor en door anderen. Daarom zijn de samenvattingen altijd betrouwbaar en actueel. Zo kom je snel tot de kern!

Veelgestelde vragen

Wat krijg ik als ik dit document koop?

Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.

Tevredenheidsgarantie: hoe werkt dat?

Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.

Van wie koop ik deze samenvatting?

Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper kaloyantitov. Stuvia faciliteert de betaling aan de verkoper.

Zit ik meteen vast aan een abonnement?

Nee, je koopt alleen deze samenvatting voor €31,53. Je zit daarna nergens aan vast.

Is Stuvia te vertrouwen?

4,6 sterren op Google & Trustpilot (+1000 reviews)

Afgelopen 30 dagen zijn er 78600 samenvattingen verkocht

Opgericht in 2010, al 14 jaar dé plek om samenvattingen te kopen

Start met verkopen
€31,53  1x  verkocht
  • (0)
  Kopen