Answer:
Program in c++ and java
Explanation:
C++ Code
#include<iostream> //for input and output
#include <string> // for string
using namespace std;
int main()
{
string firstname;
string lastname;
cout<<"Please input your first name :";
cin>> firstname;
cout<<"Please input your last name :";
cin>> lastname;
cout<< "Your name is "<< firstname << " "<<lastname;
// declaring output string stream
return 0;
}
Java Code
import java.util.Scanner;
public class SquareRoot {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter your first name :");
String firstName = scanner.next();
System.out.print("Please enter your last name :");
String lastname = scanner.next();
System.out.println("Your name is "+firstName+" "+lastname);
}
}
Output
Please input your first name :John
Please input your last name :Stone
Your name is John Stone
b. The smallest integer that can be represented by a sign-and-magnitude binary number is always 0.
c. It is impossible to store 1610 in 4-bits because overflow will occur. d. The two’s complement representation of +6710 in 8-bits is 1000011.
Answer:
a. In one’s complement format, the leftmost bit is saved for the sign where 1 indicates a negative number and 0 indicates a positive number.
Explanation:
In binary numbers, 1's complement is used to represent the signed binary numbers. In unsigned numbers, there is no need of sign. But in signed binary numbers a signed bit is required. To add the bit that is represent the sign of the number in binary, 0 represents the positive number while 1 represents the negative number.
If we have a number and want to convert it in signed binary number, we just takes it 1's complement and add the signed bit at the left of the number.
E.g.
1 = 0001
is the binary of 1, if we want to add sign, we just add the zero at left most side of the binary which make it positive as given below:
+1 = 0 0001
Now of we want to convert it into negative than, we take 1's complement in which all bits are inverted.
-1 = 1 1110
You turn your story into a rigorous and relevant video project by finding a interesting topic, after that you find solid sources to support the topic you picked.
Answer:
int count = 0; //int variables
int longest =0; // int variables
Scanner input = new Scanner(System.in); // given input is reference variable
String str= new String(); // creating object of sting class
while (input.hasNext()) // taking the input by using scanner reference
{
str= input.next(); // taking input in string
if (str.length() == longest) // checking condition
++count; // increment the count
else
if (Str.length() > longest) // if string is greater then longest
{
longest = str.length(); // calculating length
count = 1; // assign count to 1
}
}
Explanation:
Following are the description of the code :
The code that examines all the strings in the input source and determines how long the longest string (or strings are) is the following:
total = 0;% initial value is zero, in every while loop it will be incremented
while(input.hasNextInt()){
total += input.nextInt( );
}
B. Generator—genetic action
C. Thermocouple—chemical action
D. Primary cell—heat action on a device
The final listing for remember_me.py assumes either that the user has already entered their username or that the program is running for the first time. We should modify it in case the current user is not the person who last used the program.
Before printing a welcome back message in greet_user(), ask the user if this is the correct username. If it’s not, call get_new_username() to get the correct username.
Also, use a check_username() function to prevent any nested if statements from occurring in greet_user()
No prob. Let's go over the Python code,
Here's your complete Python program with the added function `check_username()`:
```
import json
filename = 'username.json'
def get_stored_username():
try:
with open(filename, 'r') as f:
username = json.load(f)
except FileNotFoundError:
return None
else:
return username
def get_new_username():
username = input("What's your username? ")
with open(filename, 'w') as f:
json.dump(username, f)
return username
def check_username():
username = get_stored_username()
if username:
correct = input(f"Are you {username}? (y/n) ")
if correct.lower() == 'y':
return username
return get_new_username()
def greet_user():
username = check_username()
print(f"Welcome back, {username}!")
greet_user()
```
Remember to call `greet_user()` to start the whole shebang. Let me know if anything needs clearing up!