C Den Önemli Bir Soru!
-
arkadaşlar yrn öglene kadar teslim etmem gereken c den ödev sorusu var ve yapamıyorum ve dersi geçmem için çok önemli bu ödev yardımcı olursanız sevinirim hocalar..
sorunun orjinali şöyle;
You are the owner of a hardware store and need to keep an inventory that can tell you what different tools you have, how many of each you have on hand and the cost of each one. Write a program that initializes the random-access file hardware.dat to 100 empty records, lets you input the data concerning each tool, enables you to list all your tools, lets you delete a record for a tool that you no longer have and lets you update any information in the file. The tool identification number should be the record number. Use the following information to start your file:

anladıgım kadarıyla dosyayı hardware.dat olarak adlandırıcaz daha sonra 100 tane boş yer ayırıcaz ve bu bilgileri giricez programda girdiğimiz kayıt numarasına göre bize miktarını,fiyatını göstericek ve bu bilgiler güncellenebilir ve silinebilir olucak ?
-
http://ul.to/l3auiq
kendı yazdıgım bısıler var oto kıralama ıle ılgılı
fiyatlama yapacaksan eger en son fprinf komutundan once
d[i] fiyat=
seklınde bı tanımlama yapıp dosyanın ıcıne atabılırsın
benım verdıgım programı edıtleyıp sunabılırsın inşallah işine yarar
** araba.txt ıcıne kayıt edıyor verılerı
-
bilseydim cvp verridim hacıı elbet birileri fikir verir
-
Verdikleri ödevin sorusu ney tam olarak türkçe yazsan cevap verebilirim
-
abi programda o tabloda verilenleri gerekli toollara atıyosun sonra liste yapıyosun orda işte seçenekler envanterdekileri görüntüle,güncelle,sil seçenekleri oluyo..sen herhangi birini seçerek onun record numarasını girerek güncelleyebiliyosun işte fiyatını veya miktarını değiştirerek veya silebiliysoun.hatta ben bu programın c++ halini buldum c ye çevirme imkanı olabilir mi? hatta c++ kodları şöle;
<!-- /* Font Definitions */ @font-face {font-family:AvantGarde-Demi; panose-1:0 0 0 0 0 0 0 0 0 0; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-format:other; mso-font-pitch:auto; mso-font-signature:3 0 0 0 1 0;} @font-face {font-family:Courier-Bold; panose-1:0 0 0 0 0 0 0 0 0 0; mso-font-charset:0; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:auto; mso-font-signature:3 0 0 0 1 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:35.4pt; mso-footer-margin:35.4pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->
2 #include <stdio.h>
using std::cout;
5 using std::endl;
6 using std::cin;
7 using std::ios;
8 using std::cerr;
9
10 #include <iomanip>
11
12 using std::setw;
13 using std::setprecision;
14 using std::setiosflags;
15
16 #include <fstream>
17 using std::ofstream;
18 using std::ifstream;
19
20 #include <cstring>
21 #include <cctype>
22 #include <cstdlib>
23
24 void initializeFile( fstream & );
25 void inputData( fstream & );
26 void listTools( fstream & );
27 void updateRecord( fstream & );
28 void insertRecord( fstream & );
29 void deleteRecord( fstream & );
30 int instructions( void );
31
32 const int LENGTH = 30;
33
34 struct Data {
35 int partNumber;
36 char toolName[ LENGTH ];
37 int inStock;
38 double unitPrice;
39 };
int main()
42 {
43 int choice;
44 char response;
45 fstream file( "hardware.dat", ios::in | ios::out );
46 void ( *f[] )( fstream & ) = { listTools, updateRecord, insertRecord,
47 deleteRecord };
48
49 if ( !file ) {
50 cerr << "File could not be opened.\n";
51 exit( EXIT_FAILURE );
52 }
53
54 cout << "Should the file be initialized (Y or N): ";
55 cin >> response;
56
57 while ( toupper( response ) != 'Y' && toupper( response ) != 'N' ) {
58 cout << "Invalid response. Enter Y or N: ";
59 cin >> response;
60 }
61
62 if ( toupper( response ) == 'Y' ) {
63 initializeFile( file );
64 inputData( file );
65 }
66
67 while ( ( choice = instructions() ) != 5 ) {
68 ( *f[ choice - 1 ] )( file );
69 file.clear(); // reset eof indicator
70 }
71
72 file.close();
73
74 return 0;
75 }
76
77 void initializeFile( fstream &fRef )
78 {
79 Data blankItem = { -1, "", 0, 0.0 };
80
81 // See Chapter 21 for a discussion of reinterpret_cast
for ( int i = 0; i < 100; ++i )
83 fRef.write( reinterpret_cast< char * >( &blankItem ), sizeof( Data ) );
84 }
85
86 void inputData( fstream &fRef )
87 {
88 Data temp;
89
90 cout << "Enter the partnumber (0 - 99, -1 to end input): ";
91 cin >> temp.partNumber;
92
93 while ( temp.partNumber != -1 ) {
94 cout << "Enter the tool name: ";
95 cin.ignore(); // ignore the newline on the input stream
96 cin.get( temp.toolName, LENGTH );
97 cout << "Enter quantity and price: ";
98 cin >> temp.inStock >> temp.unitPrice;
99 fRef.seekp( ( temp.partNumber ) * sizeof( Data ) );
100 fRef.write( reinterpret_cast< char * >( &temp ), sizeof( Data ) );
cout << "Enter the partnumber (0 - 99, -1 to end input): ";
103 cin >> temp.partNumber;
104 }
105 }
106
107 int instructions( void )
108 {
109 int choice;
110
111 cout << "\nEnter a choice:\n1 List all tools."
112 << "\n2 Update record.\n3 Insert record."
113 << "\n4 Delete record.\n5 End program.\n";
114
115 do {
116 cout << "? ";
117 cin >> choice;
118 } while ( choice < 1 || choice > 5 );
119
120 return choice;
121 }
122
123 void listTools( fstream &fRef )
124 {
125 Data temp;
126
127 cout << setw( 7 ) << "Record#" << " " << setiosflags( ios::left )
128 << setw( 30 ) << "Tool name" << resetiosflags( ios::left )
129 << setw( 13 ) << "Quantity" << setw( 10 ) << "Cost\n";
130
131 for ( int count = 0; count < 100 && !fRef.eof(); ++count ) {
132 fRef.seekg( count * sizeof( Data ) );
133 fRef.read( reinterpret_cast< char * >( &temp ), sizeof( Data ) );
134
135 if ( temp.partNumber >= 0 && temp.partNumber < 100 ) {
136 cout.setf( ios::fixed | ios::showpoint );
137 cout << setw( 7 ) << temp.partNumber << " "
138 << setiosflags( ios::left ) << setw( 30 ) << temp.toolName
139 << resetiosflags( ios::left ) << setw( 13 ) << temp.inStock
140 << setprecision( 2 ) << setw( 10 ) << temp.unitPrice << '\n';
}
142 }
143 }
144
145 void updateRecord( fstream &fRef )
146 {
147 Data temp;
148 int part;
149
150 cout << "Enter the part number for update: ";
151 cin >> part;
152 fRef.seekg( part * sizeof( Data ) );
153 fRef.read( reinterpret_cast< char * >( &temp ), sizeof( Data ) );
154
155 if ( temp.partNumber != -1 ) {
156 cout << setw( 7 ) << "Record#" << " " << setiosflags( ios::left )
157 << setw( 30 ) << "Tool name" << resetiosflags( ios::left )
158 << setw( 13 ) << "Quantity" << setw( 10 ) << "Cost\n";
159
160 cout.setf( ios::fixed | ios::showpoint );
161 cout << setw( 7 ) << temp.partNumber << " "
162 << setiosflags( ios::left ) << setw( 30 ) << temp.toolName
163 << resetiosflags( ios::left ) << setw( 13 ) << temp.inStock
164 << setprecision( 2 ) << setw( 10 ) << temp.unitPrice << '\n'
165 << "Enter the tool name: ";
166
167 cin.ignore(); // ignore the newline on the input stream
168 cin.get( temp.toolName, LENGTH );
169 cout << "Enter quantity and price: ";
170 cin >> temp.inStock >> temp.unitPrice;
171
172 fRef.seekp( ( temp.partNumber ) * sizeof( Data ) );
173 fRef.write( reinterpret_cast< char * > ( &temp ), sizeof( Data ) );
174 }
175 else
176 cerr << "Cannot update. The record is empty.\n";
177 }
178
179 void insertRecord( fstream &fRef )
180 {
181 Data temp;
182 int part;
183
184 cout << "Enter the partnumber for insertion: ";
185 cin >> part;
186 fRef.seekg( ( part ) * sizeof( Data ) );
187 fRef.read( reinterpret_cast< char * > ( &temp ), sizeof( Data ) );
188
189 if ( temp.partNumber == -1 ) {
190 temp.partNumber = part;
191 cout << "Enter the tool name: ";
192 cin.ignore(); // ignore the newline on the input stream
193 cin.get( temp.toolName, LENGTH );
194 cout << "Enter quantity and price: ";
195 cin >> temp.inStock >> temp.unitPrice;
196
197 fRef.seekp( ( temp.partNumber ) * sizeof( Data ) );
198 fRef.write( reinterpret_cast< char * >( &temp ), sizeof( Data ) );
199 }
200 else
201 cerr << "Cannot insert. The record contains information.\n";
202 }
203
204 void deleteRecord( fstream &fRef )
205 {
206 Data blankItem = { -1, "", 0, 0.0 }, temp;
207 int part;
208
209 cout << "Enter the partnumber for deletion: ";
210 cin >> part;
211
212 fRef.seekg( part * sizeof( Data ) );
213 fRef.read( reinterpret_cast< char * >( &temp ), sizeof( Data ) );
214
215 if ( temp.partNumber != -1 ) {
216 fRef.seekp( part * sizeof( Data ) );
217 fRef.write( reinterpret_cast< char * >( &blankItem ), sizeof( Data ) );
218 cout << "Record deleted.\n";
219 }
220 else
221 cerr << "Cannot delete. The record is empty.\n";
222 }
