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...
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
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...
Please do the following in python: Write a program (twitter_sort.py) that merges and sorts two twitter...
Please do the following in python: Write a program (twitter_sort.py) that merges and sorts two twitter feeds. At a high level, your program is going to perform the following: Read in two files containing twitter feeds. Merge the twitter feeds in reverse chronological order (most recent first). Write the merged feeds to an output file. Provide some basic summary information about the files. The names of the files will be passed in to your program via command line arguments. Use...
I did already posted this question before, I did get the answer but i am not...
I did already posted this question before, I did get the answer but i am not satisfied with the answer i did the code as a solution not the description as my solution, so i am reposting this question again. Please send me the code as my solution not the description In this project, build a simple Unix shell. The shell is the heart of the command-line interface, and thus is central to the Unix/C programming environment. Mastering use of...
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...
C++. Write a program that draws a rocket shape on the screen based on user input...
C++. Write a program that draws a rocket shape on the screen based on user input of three values, height, width and stages. The type of box generated (i.e.. a hollow or filled-in) is based on a check for odd or even values input by the user for the box height (or number of rows). Here is the general specification given user input for the height of the box..... Draw a hollow box for each stage if the value for...
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...
c++ Program Description You are going to write a computer program/prototype to process mail packages that...
c++ Program Description You are going to write a computer program/prototype to process mail packages that are sent to different cities. For each destination city, a destination object is set up with the name of the city, the count of packages to the city and the total weight of all the packages. The destination object is updated periodically when new packages are collected. You will maintain a list of destination objects and use commands to process data in the list....
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT