Question

In: Electrical Engineering

Analyze following program and Find Syntax errors. #include<iostream> int show(int x) int main() {     int A,B;...

Analyze following program and Find Syntax errors.

#include<iostream>

int show(int x)

int main()

{     int A,B;

      char B=10;

cout<<”Enter Value of A”;

cin<<A;

show(A)

show(50)   

      }

      cin.get();

}

int show(int x);

{

cout<<”Value is =” <<X

cout<<endl;

}

Solutions

Expert Solution

Analysis of Given Code :

#include<iostream> //including iostream header. iostream includes necessary information for program.

int show(int x) //declaring function of integer data type "show" by passing parameter x of integer data type

int main() //declaring main function. program execution is begins here.

{ //Entering into the main function.

int A,B; //Declaring two variables A,B of integer data type.

char B=10; //Declaring character data type variable B and assigning value 10 to B.

cout<<"Enter Value of A";//Printing "Enter Value of A".

cin<<A; //Taking input

show(A) //calling function show() by passing A value.

show(50) // calling function show() by passing value 50.

} //main function ends;

cin.get(); //reads input character

}

int show(int x); //defining function show().

{ //Entering into show function.

cout<<"Value is =" <<X //Printing value of X.

cout<<endl; //printing new line.

} //show() function ends.

Correct Code :

#include <iostream> //including iostream header. iostream includes necessary information for program.

using namespace std; //compiler uses std namespace

int show(int x); //declaring function of integer data type "show" by passing parameter x of integer data type

int main() //declaring main function. program execution is begins here.
{ //Entering into the main function.
int A,B; //Declaring two variables A,B of integer data type.

//char B=10; //it's an error because we are already declared variable B as integer data type.
cout<<endl; //printing new line.
cout<<" Enter Value of A"; //Printing "Enter Value of A".

//cin<<A; //it's an error because for cin we should use >>operator.
cin>>A; //Taking input from keyboard

show(A); //calling function show() by passing A value.

show(50); // calling function show() by passing value 50.
}


int show(int x) //defining function show().

{ //Entering into show function.

cout<<" Value is =" <<X //Printing value of X.

cout<<endl; //printing new line.

} //show() function ends.

Output :


Related Solutions

Complete the following program #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { // I -...
Complete the following program #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { // I - Declaring a five by five array /* II - Read data from data.txt and use them to create the matrix in the previous step*/    // III - Count and print the number of even integers in the matrix. /* IV - Calculate and print the sum of all integers in the columns with an even index value. Please note the column index begins...
C++ : Find the syntax errors in the following program. For each syntax error, fix it...
C++ : Find the syntax errors in the following program. For each syntax error, fix it and add a comment at the end of the line explaining what the error was. #include <iostream> #include <cmath> using namespace std; int main(){ Double a, b, c; 2=b; cout<<"Enter length of hypotenuse"<<endl; cin>>c>>endl; cout>>"Enter length of a side"<<endl; cin>>a; double intermediate = pow(c, 2)-pow(a, 2); b = sqrt(intermediate); cout<<"Length of other side is:" b<<endline; return 0; }
complete the program #include <cstdlib> #include <iostream> #include <iomanip> using namespace std; int main(int argc, char**...
complete the program #include <cstdlib> #include <iostream> #include <iomanip> using namespace std; int main(int argc, char** argv) { int number, sum, count; // Write a while loop that reads a number from the user and loop // until the number is divisible by 7 cout << "What is the number? "; cin >> number; while ( ... ) { ... } cout << number << " is divisible by 7!! << endl << endl; // Write a for loop that...
Question 1 Given the program below, what are the errors. #include <iostream> using namespace std; int...
Question 1 Given the program below, what are the errors. #include <iostream> using namespace std; int main() { int ind_square(int &); int x, *p; x=15; p = &x; ind_square(*p); } int ind_square(int &p) { *p = *p **p; } Question 1 options: C. No return for non-void function A. Indirection for the variables in ind_square requires pointer operand A and B B. Invalided use of address (&) symbol as a parameter for ind_squared A and C Question 2 Which statement...
#include <cstring> #include <stdio.h> #include <iostream> using namespace std; int main() {        const int...
#include <cstring> #include <stdio.h> #include <iostream> using namespace std; int main() {        const int SIZE = 20;     char str[SIZE];     char str1[SIZE];     int n;     int k =1;        printf("Enter a word: \n");     fgets(str,SIZE,stdin);     printf("Enter another word: \n");     fgets(str1,SIZE,stdin);        if (str1[strlen(str1) - 1] == '\n')     {         str1[strlen(str1)-1] = '\0';     }     if (str[strlen(str) - 1] == '\n')     {         str[strlen(str)-1] = '\0';     }      ...
What would the following program output? #include <iostream> using namespace std; int main() { char alpha...
What would the following program output? #include <iostream> using namespace std; int main() { char alpha = 'A'; for(int i = 0; i < 13; i++){ for(int j = 0; j < 2; j++){ cout << alpha; alpha++; } } cout << endl; return 0; }
What is the output of the following C program? #include<stdio.h> int fac (int x); void main(...
What is the output of the following C program? #include<stdio.h> int fac (int x); void main( ) {                         for (int i=1; i<=2; i++)                                     printf("%d", fac(i)); } int fac(int x) {                         x = (x>1) ? x + fac(x-1) : 100);                         return x; }
Consider the following program written in C syntax: void swap(int a, int b) { int temp;...
Consider the following program written in C syntax: void swap(int a, int b) { int temp; temp = a; a = b; b = temp;} void main() { int value = 2, list[5] = {1, 3, 5, 7, 9}; swap(value, list[0]); swap(list[0], list[1]); swap(value, list[value]); } For each of the following parameter-passing methods, what are all of the values of the variables value and list after each of the three calls to swap? Passed by value Passed by reference Passed...
#include "pch.h" #include <iostream> #include <stdio.h> #include <stdlib.h> #include <stdbool.h> int main() {        FILE...
#include "pch.h" #include <iostream> #include <stdio.h> #include <stdlib.h> #include <stdbool.h> int main() {        FILE *fp;        char c;        errno_t err;        err = 0;        err = fopen_s(&fp,"Desktop/test.txt", "r"); file is on my desktop but I err=2 but I don't think it is opening the file?        printf("%d\n", err);        if (err == 2)        {            printf("The file was opened\n");            while (1)       ...
Add File I/O to the voting program below #include<iostream> using namespace std; int main() {int choice;...
Add File I/O to the voting program below #include<iostream> using namespace std; int main() {int choice; int biden = 0 , trump = 0 , bugs = 0 ; int vc = 0 ; do { cout<<"\n\n\nEVOTE\n-----" <<"\n1.Joe Biden" <<"\n2.Donald Trump" <<"\n3.Bugs Bunny" // 4. Print current tally [hidden admin option] // 5. Print audit trail [hidden admin option] // 6. mess with the vote [hidden hacker option] E.C. // 7. END THE ELECTION <<"\n\n Your selection? "; cin >>...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT