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.
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
Get Answers For Free
Most questions answered within 1 hours.