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 program in JAVA: Program each option such as delete line and such. Your program will...
Please program in JAVA: Program each option such as delete line and such. Your program will be a line editor. A line editor is an editor where all operations are performed by entering commands at the command line. Commands include displaying lines, inserting text, editing lines, cutting and pasting text, loading and saving files. For example, a session where the user enters three lines of text and saves them as a new file may appear as: Menu: m Delete line:...
In this lab we will design a menu-based program. The program will allow users to decide...
In this lab we will design a menu-based program. The program will allow users to decide if they want to convert a binary number to base 10 (decimal) or convert a decimal number to base 2 (binary). It should have four functions menu(), reverse(), base2(), and base10(). Each will be outlined in detail below. A rubric will be included at the bottom of this document. Menu() The goal of menu() is to be the function that orchestrates the flow of...
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...
CSC 322 Systems Programming Fall 2019 Lab Assignment L1: Cipher-machine Due: Monday, September 23 1 Goal...
CSC 322 Systems Programming Fall 2019 Lab Assignment L1: Cipher-machine Due: Monday, September 23 1 Goal In the first lab, we will develop a system program (called cipher-machine) which can encrypt or decrypt a code using C language. It must be an errorless program, in which user repeatedly executes pre-defined commands and quits when he or she wants to exit. For C beginners, this project will be a good initiator to learn a new programming language. Students who already know...
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...