0% found this document useful (0 votes)
36 views

Assignment 1

This document summarizes a student's laboratory work on linear programs and math functions. It includes 6 tasks to complete for the laboratory work, an algorithm presented as a block diagram to solve one of the tasks, the C++ source code implementing the algorithm, and test results verifying the program works correctly for different input values.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Assignment 1

This document summarizes a student's laboratory work on linear programs and math functions. It includes 6 tasks to complete for the laboratory work, an algorithm presented as a block diagram to solve one of the tasks, the C++ source code implementing the algorithm, and test results verifying the program works correctly for different input values.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Transport and Telecommunication Institute

Laboratory work Nr 1
For course “PROGRAMMING”
The theme: Linear programs and math functions

Student: Viktors Kozorezs


Group: 4101-2BDA

Riga
2022 y.
1. Tasks for laboratory work
1) A user enters size of array: n (integer, positive).
2) Declare an one-dimensional dynamic array of integers of size n.
3) Implement filling the array by the user.
4) Display array values to the screen.
5) Calculate the sum of the positive elements of the array located between the
minimum and maximum elements (use the developed algorithm in the first
task).
6) Display the calculated sum to the screen
Calculate the average value of the array elements located after the first
negative element. The number of elements in the array is n. Array is the input
data to the algorithms.
Input: n, Array Output: Average
Individual task
Nr. 14

−√x + y 1
2 2
z= ∙
( 2 x +3 y ) √ 2
2

2. Algorithm
Figure 1 shows an algorithm for solving the problem in the form of a block diagram
х and y - input data, numeric value of double
type
z - output data, numeric value of double type
Fig.1. Algorithm

3. Source code
#include<iostream>
using namespace std;

int main()
{
float x, y;
cout << "Enter x> "; cin >> x;
cout << "Enter y> "; cin >> y;
float z = -(sqrt(x*x + y*y)) / pow((2 * x + 3 * y), 2)*(1 / sqrt(2));
cout << "z=" << z << endl;
2
system("PAUSE");
return 0;
}

4. Testing
Table 1 shows the results of testing the program
Table 1.
Program testing results
N Input data Output data
r x y Expected Received
1 0 0 No decision -1#IND
2 1 1 -0.04 -0.04
3 -1 -1 -0.04 -0.04
4 0.5 -0.123 -0.914439 -0.914439
5 -143.6 0.1 -0.00123361 -0.00123361

5. Example of running program


Figure 2 shows an example of the program's operation for input data x = 1 and y = 1.

Fig. 2. Example of running program

6. Conclusions

You might also like