1. write a program to read 10 integer elements into an array, and print the fift
ID: 3841326 • Letter: 1
Question
1. write a program to read 10 integer elements into an array, and print the fifth element to the screen?20 Points) 2..Match the following terms with the definitions given below.20 points) a. Function b. Syntax c. Semantics d. Metalanguage e. Identifier f Data type g. Variable h. Named constant i. Literal j. Expression i. An identifier referring to a value that can be changed. ii. A specific set of values, along with operations that can be applied to those values. iii. A value that appears in a program. iv. The set of rules that determines the meaning of instructions written in a programming language. v. A language that is used to write the rules for another language. vi. A subprogram in C++. vii. A name that is used to refer to a function or data object. viii. An arrangement of identifiers, literals and operators that can be evaluated. ix. The formal rules governing how valid instructions are in a programming language. x. An identifier referring to a value that cannot be changed. 3. write a function to calculate the square and cube of an integer input, and call it from the main function?(10 Points) 4. write the syntax for the following (10 points) 1. array declaration 2. function prototype 3. Structure 4. enumeration datatype declaration 5. pointer declarationExplanation / Answer
1.
#include <iostream>
using namespace std;
int main() {
// your code goes here
int a[20];
int i;
cout<<"Enter values of an array:-";
for(i=0;i<10;i++)
{
cin>>a[i];
}
cout<<"fifth element of array is: "<<a[4];
return 0;
}
2. i>variable
ii>datatype
iii> expression
iv>idenifier
v>metalanguage
vi> function
vii> literal
viii> syntax
ix> semantics
x> constant
3.
#include <iostream>
using namespace std;
int square(int a)
{
return a*a;
}
int cube(int a)
{
return a*a*a;
}
int main() {
int num;
cout<<"Enter number to find square and cube: "<<endl;
cin>>num;
int sq= square(num);
int cu =cube(num);
cout<<"sauare of num "<<num<<"is:- "<<sq<<endl;
cout<<"cube of num "<<num<<"is:- "<<cu<<endl;
return 0;
}
4. array declaration:- an array must be declared before it is used. A typical declaration for an array in C++ is:
type name [elements];
function prototype:- A function prototype is a declaration of the function that tells the program about the type of the value returned by the function and the number and type of arguments.
The prototype declaration looks just like a function definition except that it has no body i.e., its code is missing
Therefore, you can say that a function prototype has the following parts :
Here,
Since every function prototype is followed by a semicolon, so at last there will be ; as in the above function prototype.
structure:- A data structure is a group of data elements grouped together under one name. These data elements, known as members, can have different types and different lengths. Its a hetrogeneous data structure in which data structures can be declared in C++ using the following syntax:
struct type_name {
member_type1 member_name1;
member_type2 member_name2;
member_type3 member_name3;
.
.
} object_names;
Where type_name is a name for the structure type, object_name can be a set of valid identifiers for objects that have the type of this structure. Within braces {}, there is a list with the data members, each one is specified with a type and a valid identifier as its name.
for example:-
enumeration data declaration:- An enumeration is a user-defined data type that consists of integral constants. To define an enumeration, keyword enum is used.
enum{constant1, constant2,....}
example:-
pointer declaration:- A pointer is a variable whose value is the address of another variable. Like any variable or constant, you must declare a pointer before you can work with it. The general form of a pointer variable declaration is:
for example:-
5.
e) no output, it gives blank
8) area of circle:-
#include <iostream>
using namespace std;
float areaOfCircle(int radius)
{
return 3.147*radius*radius;
}
int main() {
int radius;
cout<<"Enter radius of circle "<<endl;
cin>>radius;
float area= areaOfCircle(radius);
cout<<"area of circle is:- "<<radius<<"is:- "<<area<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.