Question

1. Write complete programs. These programs should be able to compile and run. No psuedocode is...

1. Write complete programs. These programs should be able to compile and run. No psuedocode is allowed. No comments are needed. These programs will be graded for syntax, semantics, and programming style.

Write a complete program to display the results for the area of a triangle. Formula (1/2) x base x height.  

2.

Judge the correctness of the following identifiers. Write which are correct and not correct. Please note: that the ‘_’ is an underline character and not a space character. 2pts a piece

  1. __intensify

  2. _6people
  3. sales per day

  4. void5percent

  5. 4people

  6. float_data

3.

Which semicolons are erroneous in the following program? Line numbers are included to help with your answer. Be specific in your description for where ; are not needed.

1: #include; <iostream>
2: using namespace std;
3: int; main();
4: {
5: char name;;
6: cout << "My name is; " << name << endl;
7: return 0;
8: };

Homework Answers

Answer #1

Q1)

CODE:

#include <iostream>

using namespace std;

int main() {

  float base,height;

  cout<<"Enter the height of the triangle: "<<endl;

  cin>>height;

  cout<<"Enter the base of the triangle: "<<endl;

  cin>>base;

  cout<<"Area of triangle is: "<<(0.5*base*height)<<endl;

return 0;

}

OUTPUT:

Q2)

  1. __intensify - correct

  2. _6people - correct
  3. sales per day- Incorrect

  4. void5percent- correct

  5. 4people- Incorrect

  6. float_data- correct

Q3)

Question

1: #include; <iostream>
2: using namespace std;
3: int; main();
4: {
5: char name;;
6: cout << "My name is; " << name << endl;
7: return 0;
8: };

semi colon is required to terminate a statement. I have corrected the above code.

Solution

1: #include <iostream>
2: using namespace std;
3: int main()
4: {
5: char name;
6: cout << "My name is; " << name << endl;
7: return 0;
8: }

Please upvote if you like my answer and comment below if you have any queries or need any further explanation.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1. Type in the following program. Compile and run. #include <iostream> using namespace std; int main()...
1. Type in the following program. Compile and run. #include <iostream> using namespace std; int main() { ​cout << "Hello, world." << endl; } Open a Word Document and copy and paste the program and the output. 2. Create a new program: #include <iostream> using namespace std; int main() { ​float num1; ​float num2 ​float avg; ​cout << "Enter two numbers" << endl; ​cin >> num1 >> num2; ​avg = num1 + num2/2; ​cout << "The average is " <<...
Analyze the following programs and write down the output of the program. Please print every character...
Analyze the following programs and write down the output of the program. Please print every character (including whitespace character) clearly!       # include <iostream> using namespace std;   int fun( int a ) {       int b = a * 2;       return b;   }   int main()   {       int y = 5;       cout << fun(y) << endl;       cout << fun(-- y) << endl;       cout << fun(y--) << endl;       cout << y <<endl;           return 0;   }
1. Create a new project. Type in the following program. Add a comment at the top...
1. Create a new project. Type in the following program. Add a comment at the top to include your name and the date. 2. Compile and Run with different values. What data values should you choose? Think about what we discussed in class. 3. Add code to compute the modulus. Hint: you will also have to declare a new variable. //this program demonstrates the use of various operators #include <iostream > using namespace std; int main() { int num1; int...
Lab 6    -   2 Programs   -   (Lec. 6) Lab 6    -   Program #1   -   Write one...
Lab 6    -   2 Programs   -   (Lec. 6) Lab 6    -   Program #1   -   Write one number to a text file. // This program writes one number two times to a text file. (see output below) // The program uses the setprecision and fixed manipulators to format file output. // The first output simply writes the number to file, without formatting decimal places. // The second output formats the number to 2 places to the right of the decimal point....
Strings The example program below, with a few notes following, shows how strings work in C++....
Strings The example program below, with a few notes following, shows how strings work in C++. Example 1: #include <iostream> using namespace std; int main() { string s="eggplant"; string t="okra"; cout<<s[2]<<endl; cout<< s.length()<<endl; ​//prints 8 cout<<s.substr(1,4)<<endl; ​//prints ggpl...kind of like a slice, but the second num is the length of the piece cout<<s+t<<endl; //concatenates: prints eggplantokra cout<<s+"a"<<endl; cout<<s.append("a")<<endl; ​//prints eggplanta: see Note 1 below //cout<<s.append(t[1])<<endl; ​//an error; see Note 1 cout<<s.append(t.substr(1,1))<<endl; ​//prints eggplantak; see Note 1 cout<<s.find("gg")<<endl; if (s.find("gg")!=-1) cout<<"found...
Write a program that asks the user to guess a random number. The program should use...
Write a program that asks the user to guess a random number. The program should use a loop to prompt the user for the guess then display if the guess is 'too high' or 'too low'. In the end, display how many times it took to guess the number. Use the attached template.   // Chapter 5 - Lab exercise, Random Number Guessing Game // // Name: // #include <iostream> #include <cstdlib> // Needed to use random numbers #include <ctime> //...
Suppose that the file inData.txt contains the following data: 3   4 5 15.6 “Mark” “Taylor” 28...
Suppose that the file inData.txt contains the following data: 3   4 5 15.6 “Mark” “Taylor” 28 18500 3.5 B The numbers in the first line represent the Side A, Side B and Side C of a Triangle. The number in the second line represents the radius of a circle (Assume that p = 3.1416). The third line contains the first name, last name, and the age of a person. The first number in the fourth line is the savings account...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their relationship with arrays 2. To introduce the dereferencing operator 3. To introduce the concept of dynamic memory allocation A distinction must always be made between a memory location’s address and the data stored at that location. In this lab, we will look at addresses of variables and at special variables, called pointers, which hold these addresses. The address of a variable is given by...
IN C++ - most of this is done it's just missing the bolded part... Write a...
IN C++ - most of this is done it's just missing the bolded part... Write a program that creates a class hierarchy for simple geometry. Start with a Point class to hold x and y values of a point. Overload the << operator to print point values, and the + and – operators to add and subtract point coordinates (Hint: keep x and y separate in the calculation). Create a pure abstract base class Shape, which will form the basis...
Description: In this assignment, you need to implement a recursive descent parser in C++ for the...
Description: In this assignment, you need to implement a recursive descent parser in C++ for the following CFG: 1. exps --> exp | exp NEWLINE exps 2. exp --> term {addop term} 3. addop --> + | - 4. term --> factor {mulop factor} 5. mulop --> * | / 6. factor --> ( exp ) | INT The 1st production defines exps as an individual expression, or a sequence expressions separated by NEWLINE token. The 2nd production describes an...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT