marți, 11 decembrie 2018

c++ programming part three

243. Example:
244. In C++
245. #include  
246. using namespace std;
247. int main()
248. {
249. double l1,l2,l3,p,a;
250. cin>>l1;//read l1
251. cin>>l2;//read l2
252. cin>>l3;//read l3
253. p=(l1+l2+l3)/2;//calculate p
254. a = sqrt(p*(p-l1)*(p-l2)*(p-l2));//calculate area
255. cout<256. }
257. Input- read from the keyboard:
258. Think you have a pen and you can write wih him on the computer's memory.
259. 3
260. 4
261. 5

262. Output will be- display on the screen:
265. In Java
266. package javaapplication122;
267. import java.util.Scanner;
268. import java.lang.Math;
269. /*
270. * @author user
271. */
272. public class JavaApplication122 {
273.
274. /**
275. * @param args the command line arguments
276. */
277. public static void main(String[] args) {
278. // TODO code application logic here
279. Scanner ob=new Scanner(System.in);
280. double l1=ob.nextDouble();
281. double l2=ob.nextDouble();
282. double l3=ob.nextDouble();
283. double p=(l1+l2+l3)/2;

284. double a=sqrt(p*(p-l1)*(p-l2)*(p-l3));
285. System.out.println(a);
286.
287. }
288.
289. }
290. In Pascal- Lazarus
291. l1,l2,l3,p,a: real;
292. begin
293. readln(l1);
294. readln(l2);
295. readln(l3);
296. p:=(l1+l2+l3)/2;
297. a:=sqrt(p*(p-l1)*(p-l2)*(p-l3));
298. writeln(a);
299. end.
14 advice

rest on Saturday
300. Lets's assume that the data has been read and sent from a formular.html and
extracted with $POST in a php script:
301. Then in php
302. 303. $p=(l1+l2+l3)/2;
304. $a=sqrt(p*(p-l1)*(p-l2)*(p-l3));
305. echo $a;
306. ?>
307. That's why I said you do not have concentrate about syntax, but on logic.
308. Arrays
309. An array is a set of elements of the same type. The arrays are simple
structured types. statement of declaring an array of a dimension is the following:
310. type array_name [an integer number];
311. where integer_number represents the maximum number of elements of the
array. The elements of the array are array_name [0], array_name [1], ..., array_name
[19]. For example, the statement:
312. int a [11];
313. declares a vector called "a" with 11 integer number.
314. If the array are a [0], a [1], ..., a [9]. You notice the first indexof the table is 0,
and the last must be a[10].
315. An array can be initialized when we write the elements between the
braces{}. Example:
316. statement int x [3] = {4,2,11}; declare an array, called "x" and assign some values
317. x[0]=4;
318. x[1]=2;
319. x[0]=11;
320. If the list of values ??is shorter than the number of declared items, the last
items are initialized with zero. In the case of initiating an array, we can omit the
number of elements in the array.

321. For example, we can write
322. int x [] = {2,4,6};
323. The compiler calculates the size of the array, and the size, in this case, must be
3. The previous statement is equivalent to the statement:
324. int x [3] = {2, 4, 6};
325. An array can have more than one dimension.
326. For example, the statement:
327. int an [7] [4];
328. declares an array of seven lines and three columns. Array called "an" can have
these
329. elements:
330. an [0] [0] an [0] [1] an [0] [2] an[0] [3]
331. ... ... ...
332. an [6] [0] an [6] [1] an [6] [2] an [6] [3]
333. Equal statement
334.
335. operator =value assigns a value to a variable.
336. Or:
337. variable = expression;

338. The sign " = " is not the equal sign of mathematics.
339. Is called the assignment sign.
340. Think like that: cover what is on the left of the sign " = ", calculate what is on the
right of the sign " = ", (if is necessary), and the result is assigned to the left member.
341. Example:
342. a=21
343. Means:
344. Think like that: cover what is on the left of the sign " = ", calculate what is on the
right of the sign " = ", (if is necessary), and the result is assigned to the left member.
345. Example:
346. a=21;
347. Think like that: cover what is on the left of the sign " = ", (a), calculate what is
on the right of the sign " = ", (if is necessary, and in this case is not, is only a value,
21), and the result is assigned to the left member, means "a " has received value 21.
348. Other example:
349. x=2
350. y=3-x
351. Think like that: cover what is on the left of the sign " = ", (x), calculate what is
on the right of the sign " = ", (if is necessary, and in this case is not, is only a value, 2),
and the result is assigned to the left member, means "x " has received value 2.
352. Again, think like that: cover what is on the left of the sign " = ", (y), calculate
what is on the right of the sign " = ", (and is necessary, x has value 3, and 3 minus
x, means 3 minus 2, and the result will be 1). "y " has received value 1.
353. For example, the following statements:
354.
355. a=2
356. a=a+1
357. Means:
358.
359. Think like that: cover what is on the left of the sign " = ", (a), calculate what is
on the right of the sign " = ", (if is necessary, and in this case is not, is only a

value, 2), and the result is assigned to the left member, means "a " has received
value 2.

360. Again, think like that: cover what is on the left of the sign " = ", (a),
calculate what is on the right of the sign " = ", (and is necessary, a has value 2,
and a plus 1, means 2 plus 1, and the result will be 3). "a " has received value 3.
361.
362.
363.
364. Mathematically speaking, there is not in this world, a number to wich if i add
1, the number will remain the same as the one before.
365.
366. int x, y;
367. x = 23; x become 23.
368.
369.
370. y = 2 * x; y become 46 (2*x means 2*23, whih is equal with 46).
371. The equal statement is not the same with the mathematic equal.
372.
373. The following statement calculates the value of its expression.
374. 2 multiplied by x, ie 46, and assigns this value to y.
375. Languages ??C and C ++ have special expression.
376. Let's a variable x and an expression e.
377. x op = e
378. is equivalent to
379. x = x op e
380. The following table lists these operators
381. statement: x = x + e short form: x + = e
382. statement: x = x – e short form: x - = e
383. statement: x = x * e short form: x * = e
384. statement: x = x / e short form: x + = e
385. statement: x / = e short form: x + = e
386. statement: x = x% e short form: x% = e
387. The statements are executed from right to left.
388. Statement:
389. z = 1;
390. x = y = z;
391. y take the value of z, so y= 1, and x will be the value of the y, that is 1.

392. Statement:

393. x + = y + = z;
394. y + = z;
395. is equivalent to y = y + z. Evaluating the expression from right side: y + z, will
be 2, because y and z were equal to 1.
396. The value is attributed to y, y = 2.
397. Statement:
398. x + = y;
399. is equivalent to x = x + y. Evaluate the expression on the part right: x + y,
will produce 3. The value is assigned to x, x = 3.
400. Function libraries
401. C and C ++ languages ??have standard prototype libraries. These libraries
are announced with the directive includes.
402. # includes  
403. These libraries are files with the h extension and are called "header".
404. For example, the library with prototypes of mathematical functions is
. In order to be notified, we will write the statement: 
405. # includes  
406. The library with C type input / output functions is
407. The library with C-mode strings is
408. The library with C ++ input / output functions is
409. Input / output operations
410. In any program there is a standard input file, that is keyboard and an output
file that is the screen. In the programany file is associated with an object called
stream. Stream of the input associated with the keyboard is called cin, the output
stream associated with the screen is called cout.
411. The write operator is <<. He inserts data into the stream cout. For example,
the statements:
412. int i = 124;
413. cout << "i =" << i;


414. display on the screen:
415. i = 124
416. The reader from a stream is >>. He extracts data from the stream. The operator
>> is followed by the name of the variable andwill save the read value. For example,
the statements:
417. int a;
418. cin >> a;
419. will read the value entered from the keyboard and assign itvariable a. You
can read as many data as possible from the cin stream.
420. Statement:
421. cin >> a >> b;
422. is equivalent to:
423. cin >> a;
424. cin >> b;
425. The prototype library for cin and cout have the name
426. Main function
427. Any program written in C or C ++ languages ??consists of functions that
call one another. Definition of a function it is:
428. data_type name_of_the_function type (list of the parameters)
429. {
430. statements
431. }
432. One of the functions has the main name and the program execution start from
here. The prototype of this function is:
433. int main ();


434. An example:
435. # includes  
436. int main ()
437. {
438. int i, j;
439. cout << "enter a full value";
440. / * reads a full value * /
441. cin >> i;
442. cout << "the value you entered is << << i;
443. / * calculate square of read value * /
444. j = i * i;
445. / * write the calculated value * /
446. cout << "the square of the value is" << j;
447. return 0;
448. }
449. Note that the main () function returns 0 with the statement:
450. return 0;
451. Operators ++ and - -
452. The ++ operator increments an entire variable with one, the operator -
- decrements an entire variable with one.
453. These operators can be a prefix, that is, so we can write:
454. ++ x, - -x or postfix x ++, x- -
455. Operator's prefix, ++ x, -- x.
456. Increments or decrements the value of the variable by one.
457. Example. Either the variable:
458. int i = 1, x;


Niciun comentariu:

Trimiteți un comentariu

Rețineți: Numai membrii acestui blog pot posta comentarii.