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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
|
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <windows.h>
using namespace std;
void gotoxy( int column, int line )// Positioniong of cursor.
{
COORD coord;
coord.X = column;
coord.Y = line;
SetConsoleCursorPosition(
GetStdHandle( STD_OUTPUT_HANDLE ),
coord
);
}
int wherex()
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
COORD result;
if (!GetConsoleScreenBufferInfo(
GetStdHandle( STD_OUTPUT_HANDLE ),
&csbi
))
return -1;
return result.X;
}
int wherey()
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
COORD result;
if (!GetConsoleScreenBufferInfo(
GetStdHandle( STD_OUTPUT_HANDLE ),
&csbi
))
return -1;
return result.Y;
}
void ClearScreen()// Clearing the screen.
{
HANDLE hStdOut;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD count;
DWORD cellCount;
COORD homeCoords = { 0, 0 };
hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
if (hStdOut == INVALID_HANDLE_VALUE) return;
/* Get the number of cells in the current buffer */
if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
cellCount = csbi.dwSize.X *csbi.dwSize.Y;
/* Fill the entire buffer with spaces */
if (!FillConsoleOutputCharacter(
hStdOut,
(TCHAR) ' ',
cellCount,
homeCoords,
&count
)) return;
/* Fill the entire buffer with the current colors and attributes */
if (!FillConsoleOutputAttribute(
hStdOut,
csbi.wAttributes,
cellCount,
homeCoords,
&count
)) return;
/* Move the cursor home */
SetConsoleCursorPosition( hStdOut, homeCoords );
}
struct dvd{
int looping;
char num[8];
char name[30];
char title[50];
float price, cash;
};
dvd dvd[30],cust;
FILE *fp;
void mainUI()
{
gotoxy(36,3);
printf("Video City");
gotoxy(34,4);
printf("Rental System");
gotoxy(18,7);
printf("[1]Rent DVDs [2]Add new DVDs");
gotoxy(18,9);
printf("[3]View Available DVDs [4]Transactions Made");
gotoxy(36,12);
printf("[5]Exit");
gotoxy(18,16);
printf("Option: ");
}
void addProdsInput()
{
int x=0;
char c;
printf("Product No. : ");
scanf("% *c",dvd[x].num);
scanf("%s",&dvd[x].num);
printf("Enter a title : ");
scanf("% *c",dvd[x].title);
gets(dvd[x].title);
printf("Price: ");
scanf("% *c",dvd[x].price);
scanf("%f",&dvd[x].price);
getchar();
printf("\nDVD: %s %s PHP %.2f",dvd[x].num,dvd[x].title,dvd[x].price);
}
void addProds()
{
char ans,ans1;
int x=0;
do{
ClearScreen();
addProdsInput();
gotoxy(0,5); printf("Save this product?[Y/N]: ");
ans=getchar();
if(ans=='Y' || ans=='y')
{
fp=fopen("DVD.TXT","a");
if(!fp)
{
printf("Could not open file!");
exit(101);
}
else
{
fprintf(fp,"\n%s %s %.2f ",dvd[x].num,dvd[x].title,dvd[x].price);
gotoxy(0,6); printf("Record Saved!!!\n");
}
if (fclose(fp)==EOF)
{
printf("Could not close file!!!");
exit(201);
}
}
else if(ans=='N' || ans=='n')
printf("Data Not SAVED!");
else
printf("\nInvalid INPUT! GOODBYE!");
gotoxy(0,8); printf("Add New Product?[Y/N]: ");
scanf("%s",&ans1);
getchar();
getchar();
}while(ans1=='Y' || ans1=='y');
if(ans1=='N' || ans1=='n')
printf("Thank you! :D");
else
{
printf("\nInvalid Input");
getchar();
exit(1);
}
}
void viewProds()
{
char ans,ans1,ans_;
int x=0;
ClearScreen();
gotoxy(35,1);
printf("View DVDs");
gotoxy(8,4);
printf("DVD No.");
gotoxy(30,4);
printf("Title");
gotoxy(48,4);
printf("Price");
gotoxy(65,4);
printf("Available");
{
fp=fopen("DVD.TXT","r");
if(!fp)
{
printf("Could not open File!!!");
exit(101);
}
else
{
while(fscanf(fp,"%s %s %f", &dvd[x].num, &dvd[x].title, &dvd[x].price)!=EOF) //%.2f
{
gotoxy(8,6+x);
printf("%s",dvd[x].num);
gotoxy(30,6+x);
printf("%s",dvd[x].title);
gotoxy(49,6+x);
printf("%.2f",dvd[x].price);
x++;
}
}
if(fclose(fp)==EOF)
{
printf("Could not close file!!!");
exit(201);
}
printf("\n\n\n");printf("-----------------------------------!End of List!--------------------------------");
getch();
}
}
main()
{
int opt;
do{
ClearScreen();
mainUI();
scanf("%d",&opt);
getchar();
// if(opt==1)
if(opt==2)
addProds();
else if(opt==3)
viewProds();
else if(opt==5)
{
ClearScreen();
gotoxy(26,12); printf("Thank You Very Much! GOODBYE!");
getchar();
exit(0);
}
else
{
ClearScreen();
gotoxy(33,12); printf("Invalid input");
}
}while(opt>=1 && opt<=5);
getch();
return 0;
}
|