Quiz 05, Amazing codes!

--Originally published at Programming the city

Hey there guys, I just finished the 5 codes of the quiz.

I was in trouble in creating the first two codes because I didn’t know what they were supposed to do. But I visited Ken’s office and then everything was clear.

I really liked this course, because c++ is a language too wide so you can do whatever you want to achieve.

Here is the firts code. Advice: Be careful in where do you type the printf’s or the couts.

a

Result:

a


 

Second Code: Remember to include the stdio.h library

a

Reslult:

a


 

Third code: You may think its too difficult to créate a triangle with letters ina c++, but what you just need to do is to press space and put the letters in shape.

a

Result:

a

————————————————————-

 

Fourth code: In this code, I did it in a larger way, but you can do it smaller as you want.

aa

 

Result:

a

 


Fifth code: This was the easiest code.

aa

Result:

a


Quiz #5

--Originally published at my programming blog

The quiz of this week was very tricky, I needed to do the first 5 exercises in this page, at first I was a little bit confused with the first two exercises, but once the teacher explained me it was that hard.

  1. For the first exercise I tested the code and tried to correct it based on the errors the terminal gave me, then thanks to Ken and the page he gave us, I was able to correct the program completely.

screen-shot-2017-02-15-at-3-38-22-pm

2. For the second exercise I asked the user for an integer, a character and a float, and I made an integer called x that would be equal to the integer/character/float converted. So what I did was to equal x to “(type) a” where a= to the value that the user enters (the int, float or char). I did this before each message that the program prints, changing the value of x each time. I learned this method thanks to this page.

screen-shot-2017-02-15-at-3-39-06-pm

3. In the third exercise what I needed to do was to make a program that could print this:

Screen Shot 2017-02-16 at 9.39.47 AM.png

What I did was to do it from scratch, counting spaces etc. It was a bad idea!! Because I wasted a lot of time and when I finished  Ken told the class that by copy pasting it it would be very easy, which made me mad because I didn’t think about that. screen-shot-2017-02-15-at-3-39-44-pm

4. For the fourth exercise needed to ask the user for three numbers and then print those numbers but in ascending order. What I did was well first to ask the user for the three numbers, then I did nested ifs, for example: My first if’s condition was if a>b and inside that if I entered another if with the condition if b>c and then

screen-shot-2017-02-15-at-3-40-04-pm
screen-shot-2017-02-15-at-3-40-19-pm
screen-shot-2017-02-15-at-3-40-37-pm
screen-shot-2017-02-15-at-3-37-45-pm
Continue reading "Quiz #5"

Quiz week 6

--Originally published at The Clueless Programmer

So for the quiz on this week we had to do a bunch of programs, so expect this blog post so be filled with codes, don´t be scared though, they´re not so hard. The excercises we had to do came out of this web page: http://www.utdallas.edu/~ivor/cs1315/clabs96.html

Excercise 1: They gave us a program and we had to make it run. We added some stuff at the beginning and then we had to add a library and change the couts to printfs.

#include <iostream>
#include <stdio.h>

using namespace std;
int main()
{ /* PROGRAM TO PRINT OUT SPACE RESERVED FOR VARIABLES */
char c;
short s;
int i;
unsigned int ui;
unsigned long int ul;
float f;
double d;
long double ld;
cout << endl
<< “The storage space for each variable type is:”
<< endl;
printf(“char: \t\t\t%d bits”,sizeof(c)*8); // \t means tab
printf(“short: \t\t\t%d bits”,sizeof(s)*8);
printf(“int: \t\t\t%d bits”,sizeof(i)*8);
printf(“unsigned int: \t\t%d bits”,sizeof(ui)*8);
printf(“unsigned long int: \t%d bits”,sizeof(ul)*8);
printf(“float: \t\t\t%d bits”,sizeof(f)*8);
printf(“double: \t\t%d bits”,sizeof(d)*8);
printf(“long double: \t\t%d bits”,sizeof(ld)*8);
}

Excercise 2: We had to ask the user to input a char, an int and a float value and then we had to print each value as the other two. Like give the char and the float value of an int.

#include <iostream>
using namespace std;
int main()
{
char c1;
int n1;
float f1;
cout<<“Write a single character: “;
cin>>c1;
cout<<“Write an integer: “;
cin>>n1;
cout<<“Write a float: “;
cin>>f1;
int n2=int(c1);
float f2=float(c1);
cout<<“The character “<<c1<<” when cast to an int gives value: “<<n2<<endl;
cout<<“The character “<<c1<<” when cast to a float gives value: “<<f2<<endl;
char c2=char(n1);
float f3=float(n1);
cout<<“The integer “<<n1<<” when cast to a char gives value: “<<c2<<endl;
cout<<“The integer “<<n1<<” when cast to a float gives value: “<<f3<<endl;
int n3=int(f1);
char c3=char(f1);

Continue reading "Quiz week 6"