Question

1. Vim commands: a. How do you auto indent your program? b. Explain what the following...

1. Vim commands: a. How do you auto indent your program? b. Explain what the following commands do: dd, y3, p, :set cindent (1 pt) VIM exercises These exercises on the computer need to be repeated by each student in the pair. This is to ensure that both students understand how to get around in Linux!!! For this part of the lab, you will create a .vimrc file that will help you develop your C++ programs using VIM. First, we need to create a simple .vimrc file in your home directory on the ENGR (flip) server. vim .vimrc In this file, you can insert the following lines so that it makes working with vim easier. Comments are prefaced with a quotation mark, “. filetype on filetype plugin on filetype indent on autocmd FileType c, cpp set cindent “This allows for c-like indentation 2 set sw=3 “Set the sw for the auto indent to 3 spaces set number “Show the line numbers on the left “Change the color of the text and turn on syntax highlighting “color desert color torte colorscheme evening syntax on “Turn on syntax highlighting set showmatch “Show matching braces set showmode “Show current mode “When one of the chars is typed, the matching is typed and the cursor moves left “The line below is single quotes inoremap ' '' “The line below is double quotes inoremap " "" inoremap { {} inoremap ( () There are many more commands you can insert in this file, and here is a reference guide to some of these: http://vimdoc.sourceforge.net/htmldoc/starting.html

(2 pts) Testing and Debugging Download the following cpp file. (Use wget command) http://classes.engr.oregonstate.edu/eecs/fall2020/cs161-001/labs/buggyCode.cpp You must find as many bugs as possible and fix them. Some are logic errors, some are syntax errors. Hint: there are 21 bugs, some are obvious, some are more complex. Make sure you re-compile and run your program after you make a single fix to a mistake to make sure you actually fixed the mistake, didn’t introduction new errors, and/or eliminated other errors as a result of the fix. Here’s an example output after catching all errors: (User inputs are underlined)

y is set to: 3

please enter a number for y: 5

X is less than Y

Would you like to input another number?

1

please enter a number for y: 3

X is equal to Y

Would you like to input another number?

0

0

1

2

3

4

5

6

7

8

9

what number would you like to find the factorial for?

10

3628800

Are you enjoying cs161? (y or n)

y

YAY

(1 pt) Design atoi atoi() is a common function which takes a character and returns its decimal ASCII value. Start by designing how this function will work. It should take any character found on the ASCII chart (http://www.asciitable.com/) and return the decimal value. /******************************************************************** ** Function: a_to_i ** Description: turns a character into a decimal value ** Parameters: char character ** Pre-Conditions: the input is a character ** Post-Conditions: returned the decimal value of the character ********************************************************************/ (2 pts) Implement atoi Write the a_to_i() function based on your design. Test your function thoroughly. Will your function properly return the decimal value of: ‘A’, ‘1’, ‘b’, ‘/’, ‘ ‘, etc.? (1 pt) Design itoa Similar to a_to_i(), i_to_a() takes an integer and returns the character associated with that value. Design this function. /******************************************************************** ** Function: i_to_a ** Description: turns a decimal value into a character value ** Parameters: int decimal ** Pre-Conditions: the input is an integer ** Post-Conditions: returned the character which represents the decimal value ********************************************************************/ (2 pts) Implement itoa Write the i_to_a() function. Test your function thoroughly. Will it return the correct character value for 127, 65, 97, etc.? For this exercise, you can assume that the input will not be less than 0 or greater than 127.

Homework Answers

Answer #1

program code to copy

#include <iostream>

using namespace std;

int main()
{
        int x=3, y, num, total=1;
        char myAnswer;

        y=x;
        cout<< "y is set to: " << y << endl;

        cout<< "Please input a number for y: " << endl;
        cin>> y ;

        bool again=true;
        while(again)
        {
                if(x>y)
                {
                        cout<< "X is greater than Y. " << endl;
                        cout<< "Would you like to input another number? 1 for yes and 2 for no." << endl;
                        cin>> y;
                        if(y==1)
                        {
                                cout<< "Enter a new number for y: " ;
                                cin>> y ;
                        }   
                        else   
                        again=false;
                }        
                else if(x<y)
                {
                        cout<< "X is less than Y." << endl;
                        cout<< "Would you like to input another number? 1 for yes and 2 for no." << endl;
                        cin>> y ;  
                        if(y==1)
                        {
                                cout<< "Enter a new number for y: " ;
                                cin>> y ;
                        }   
                        else   
                        again=false;
                }
                else
                {
                        cout<< "Xand Y are equal. Would you like to input another number? 1 for yes and 2 for no." << endl;
                        cin>> y ;
                        if(y==1)
                        {
                                cout<< "Enter a new number for y: " ;
                                cin>> y ;
                        }   
                        else   
                                again=false;
                }        
        }
        for(x=0; x < 10; x++)
        cout<< x << endl;

        cout<< "What number would you like to find the factorial for? " << endl;
        cin>> num ;
        for(int x = num; x > 0; x--)
        total = total* x;
        cout<< total << endl;
        cout<< "Arer you enjoying cs161? (y or n) " << endl;
        cin>> myAnswer ;
        if(myAnswer == y)
        cout<< "YAY!" << endl;
        else
        cout<< "YOU WILL SOON!" << endl;
        return 0;
}

sample output

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
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
1. Given the following multi-way if statement, provide a switch statement, using proper java syntax, that...
1. Given the following multi-way if statement, provide a switch statement, using proper java syntax, that will provide the same function. Char grade; String tstmsg; if (grade == ‘A’) {   tstmsg = “Excellent”; } else if (grade == ‘B’) {   tstmsg = “Good”; } else if (grade == ‘C’) {   tstmsg = “OK”; } else {   tstmsg = “Study More”; } 2.Write the following for statement as a while statement. for (k = 0; k < 3; k++) {   System.out.println...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
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...
Program will allow anywhere between 1 and 6 players (inclusive). Here is what your output will...
Program will allow anywhere between 1 and 6 players (inclusive). Here is what your output will look like: Enter number of players: 2 Player 1: 7S 5D - 12 points Player 2: 4H JC - 14 points Dealer: 10D Player 1, do you want to hit? [y / n]: y Player 1: 7S 5D 8H - 20 points Player 1, do you want to hit? [y / n]: n Player 2, do you want to hit? [y / n]: y...
Write a Python 3 program called “parse.py” using the template for a Python program that we...
Write a Python 3 program called “parse.py” using the template for a Python program that we covered in this module. Note: Use this mod7.txt input file. Name your output file “output.txt”. Build your program using a main function and at least one other function. Give your input and output file names as command line arguments. Your program will read the input file, and will output the following information to the output file as well as printing it to the screen:...
In this assignment you will analyze the performance of actual company divisions. FASB ASC 280 (formerly...
In this assignment you will analyze the performance of actual company divisions. FASB ASC 280 (formerly SFAS 131) requires publicly traded companies to disclose segment information in the notes to the financial statements. You will use Excel to create visually appealing data tables and bar charts to analyze division performance, and then comment on the results.    Due Date: Tuesday, May 1, 2018.   Submit as an attachment in Blackboard in the Module 24 Assignment. SECTION I The link is to...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From the April 2004 Issue Save Share 8.95 In 1991, Progressive Insurance, an automobile insurer based in Mayfield Village, Ohio, had approximately $1.3 billion in sales. By 2002, that figure had grown to $9.5 billion. What fashionable strategies did Progressive employ to achieve sevenfold growth in just over a decade? Was it positioned in a high-growth industry? Hardly. Auto insurance is a mature, 100-year-old industry...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT